指针与多维数组深度剖析
源码
[root@luozhonghua ch10]# cat zippo11.c
/* zippo1.c -- zippo info */#include <stdio.h>
int main(void)
{
int b[3]={100,200,300}; int *p;p=b;
printf("b=%p,*b=%d,p=%p,*p=%d,p+1=%p,*p+1=%d \n",b,*b,p,*p,p+1,*p+1);
printf("---------------------------\n");
int zippo[4][2] = { {2,4}, {6,8}, {1,3}, {5, 7} };
printf(" zippo = %p, zippo + 1 = %p\n",
zippo, zippo + 1);
printf("zippo[0] = %p, zippo[0] + 1 = %p\n",
zippo[0], zippo[0] + 1);
printf(" *zippo = %p, *zippo + 1 = %p\n",
*zippo, *zippo + 1);
printf("zippo[0][0] = %d\n", zippo[0][0]);
printf(" *zippo[0] = %d\n", *zippo[0]);
printf(" **zippo = %d\n", **zippo);
printf(" zippo[2][1] = %d\n", zippo[2][1]);
printf("*(*(zippo+2)) = %d\n", *(*(zippo+2)));
printf("*(*(zippo+2) + 1) = %d\n", *(*(zippo+2) + 1));
printf("---------------------------\n");
printf("*(*(zippo+1)) = %d\n", *(*(zippo+1)));
printf("*(*(zippo+1) + 1) = %d\n", *(*(zippo+1) + 1));
printf("*(*(zippo)) = %d\n", *(*(zippo)));
printf("*(*(zippo)+1) = %d\n", *(*(zippo)+1));
return 0;
}
结果:
[root@luozhonghua ch10]# ./zippo11
b=0xbfda6dd0,*b=100,p=0xbfda6dd0,*p=100,p+1=0xbfda6dd4,*p+1=101
---------------------------
zippo = 0xbfda6db0, zippo + 1 = 0xbfda6db8
zippo[0] = 0xbfda6db0, zippo[0] + 1 = 0xbfda6db4
*zippo = 0xbfda6db0, *zippo + 1 = 0xbfda6db4
zippo[0][0] = 2
*zippo[0] = 2
**zippo = 2
zippo[2][1] = 3
*(*(zippo+2)) = 1
*(*(zippo+2) + 1) = 3
---------------------------
*(*(zippo+1)) = 6
*(*(zippo+1) + 1) = 8
*(*(zippo)) = 2
*(*(zippo)+1) = 4
地瓜园