首页 > 其他 > 详细

指针与多维数组深度剖析

时间:2014-08-20 12:31:32      阅读:211      评论:0      收藏:0      [点我收藏+]

源码

[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


指针与多维数组深度剖析,布布扣,bubuko.com

指针与多维数组深度剖析

原文:http://blog.csdn.net/luozhonghua2014/article/details/38704141

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!