#include <stdio.h>
void test(int *arr, int n)
{
for(int i = 0; i < n; ++i)
printf("%d ", *(arr + i));
printf("\n");
}
int main(void) {
int a[10] = { 1,2,3,4,5,6,7,8,9,10};
test(a,10);
return 0;
}
this gives the correct answer which is "1 2 3 4 5 6 7 8 9 10
"
but when I change first argument's type in test
function to *arr[]
it gives
1 3 5 7 9 0 0 965108401 262144 404875544
looks like i += 2
happens in for
loop.
The changed code is below
#include <stdio.h>
void test(int *arr[], int n)
{
for(int i = 0; i < n; ++i)
printf("%d ", *(arr + i));
printf("\n");
}
int main(void) {
int a[10] = { 1,2,3,4,5,6,7,8,9,10};
test(a,10);
return 0;
}
What *arr[]
actually is?