首页 > 代码库 > 指针与多维数组深度剖析
指针与多维数组深度剖析
源码
[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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。