#include <stdio.h>
void
foo (int (*ptr)[10]) {
(*ptr[0])++;
(*ptr[1])++;
(*ptr[4])++;
}
int
main(int argc, char **argv) {
int i;
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
foo(&arr);
for (i = 0; i < 10; i++) {
printf ("%d ", arr[i]);
}
printf ("\n");
return 0;
}
vm@ubuntu:~/src/tcpip_stack$ gcc test.c
vm@ubuntu:~/src/tcpip_stack$ ./a.out
2 2 3 4 5 6 7 8 9 10
*** stack smashing detected ***: terminated
Aborted (core dumped)
How to access the individual elements of the array through array pointer in foo ( ) ? Here it seems like, in foo() , based on array index, the entire array is being jumped as many times as index value.