I'm new to c and I have trouble with arrays in c. I don't know how to assign first element from an array to an int variable. When I tried, I got a random large integer from nowhere even index was in range.
This is part of my code:
int solve(int *elev, int n)
{
for (int i = 0; i < n; ++i)
printf("%d ", elev[i]);
putchar('\n');
printf("%d %d %d %d %d\n", elev[0], elev[1], elev[2], elev[3], elev[4]);
int low = elev[0];
int high = elev[4];
printf("low:%d high:%d\n");
// ...
}
Partial output:
1 4 20 21 24
1 4 20 21 24
low: 362452 high: 7897346
What was a cause of above output?
highis likely to beelev[n-1](assuming n>0 andelev[]is sorted)