/* 想实现数组元素依次输出,利用指针的移动 为什么这样写不行啊? */ # include <stdio.h> int shuzu[2][2] = {1, 2, 3, 4}; int * p = &shuzu[2][2]; void main(void) { int i; for (i=0; i<4; i++) { p++; printf("%d\n", * p); } }
# include <stdio.h> int shuzu[2][2] = {1, 2, 3, 4}; int * p = shuzu;//数组名就是数组的首地址 所以不用取地址运算符 ‘& ’ void main(void) { int i; for (i=0; i<4; i++,p++) printf("%d\n", * p); }
# include <stdio.h> int shuzu[2][2] = {1, 2, 3, 4}; int *p = &shuzu[0][0]; void main(void) { int i,j; for (i=0,j=0; i<4; i++) { printf("%-3d", *(p++)); j++; if(!(j%2)) printf("\n"); } }
# include <stdio.h> int shuzu[2][2] = {1, 2, 3, 4}; int *p = shuzu; void main(void) { int i,j; for (i=0;i<4;i++) { printf("%d",p+i); } return 0; }