I have this very simple code:
#include <stdio.h>
#include <stdlib.h>
int maxArr(int *arr)
{
int i=0;
for (i = 0; i < 10; ++i)
{
printf("%d\n",arr[i]);
}
return 0;
}
int main()
{
int* i = {0,1,2,3,4,5,6,7,8,9};
maxArr(&i);
return 0;
}
but instead of printing 0,1,2,3,4,…,9
I’m getting this:
0
0
0
0
0
0
1809693728
32767
203279940
1
Why?
You need to pass in
i, not&iInstead of iterating through the array, you are iterating through memory addresses starting at
&i.