标题:[实践OK]指针数组和数组指针的理解。 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Wed, 07 Sep 2016 16:11:20 +0000 作者:jackxiang 地址:http://jackxiang.com/post/8936/ 内容: 背景:在Linux下的c也好windows下的c也好,这两者不太好理解,再研究一下,指针数组就是像数组下标一样获取一个数组里面的值,不过前面有括号(*b)[N],N {1,N}。 1、指针数组:array of pointers,即用于存储指针的数组,也就是数组元素都是指针;数组指针:a pointer to an array,即指向数组的指针。 int* a[4] 指针数组 表示:数组a中的元素都为int型指针 元素表示:*a[i] *(a[i])是一样的,因为[]优先级高于* int (*a)[4] 数组指针 表示:指向数组a的指针 元素表示:(*a)[i] 2、下面通过实例来说明数组指针与指针数组的区别: #include int main() { int c[4]={1,2,3,4}; int *a[4]; // 指针数组 int (*b)[4]; // 数组指针 int i=0; int j=0; b=&c; // 将数组c中元素赋给数组a for(i=0;i<4;i++) { a[i]=&c[i]; } // 输出看下结果 printf("%d\n",*a[1]);// 输出2 printf("%d\n",(*b)[1]);// 输出2 printf("%d\n",(*b)[2]);// 输出3 for(i=0;i<4;i++) { printf("value at %p = %d\n",(b[0]+i),*(b[0]+i)); } return 0; } [1]+ Stopped vim arrpoint.c [root@iZ88qk71ph8Z tmp]# gcc arrpoint.c [root@iZ88qk71ph8Z tmp]# ./a.out 2 2 3 value at 0x7fff169da510 = 1 value at 0x7fff169da514 = 2 value at 0x7fff169da518 = 3 value at 0x7fff169da51c = 4 Generated by Jackxiang's Bo-blog 2.1.1 Release