In my main()
function I create an array, find the address of the highest value and increase the value at the address:
int main()
{
int i[5] = {2,5,6,5,3};
int *pi = getAdres(i);
(*pi)++;
printf("%d", i[2]);
return 0;
}
The getAdres()
function looks like:
int getAdres(int *i)
{
int *pi;
int higest = 0;
for(int j = 0; j < 5; j++)
{
if(i[j] > higest)
{
pi = &i[j];
higest = i[j];
}
}
return pi;
}
Without making the get address part into a function it works but in the current format (*pi)++;
is giving me a segmentation fault.
What is going wrong?