#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 est.c
Vm@ubuntu:~/src/tcpip_STACK$./a.out
二、二、三、四、五、六、七、八、九、十.
*检测到堆栈粉碎*:已终止
已中止(核心转储)
如何通过foo()中的数组指针访问数组的各个元素? 在这里,在foo()中,基于数组索引,整个数组的 skip 次数与索引值一样多.