loong qiang
像风一样自由

C语言指针理解

#include <stdio.h>
int main(void){
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 =  %d\n",**zippo);
printf("    *zippo[0] = %d\n",*zippo[0]);
printf("    zippo[2][1] = %d\n",zippo[2][1]);
printf("    *(*(zippo + 2) + 1) = %d\n",*(*(zippo + 2) + 1));
printf("    zippo = %p,&zippo = %p,&zippo[0] = %p,zippo[0] = %p,&zippo[0][0] = %p,zippo[0][0] = %d\n",zippo,&zippo,&zippo[0],zippo[0],&zippo[0][0],zippo[0][0]);

printf("    *(*(zippo + 1) + 2) = %d,zippo[1][2] = %d\n",*(*(zippo + 2) + 1),zippo[1][2]);
printf("    &zippo[0][0] = %p,&zippo[0][1] = %p,&zippo[1][0] = %p,&zippo[1][1] = %p,&zippo[2][0] = %p,&zippo[2][1] = %p,&zippo[3][0] = %p,&zippo[3][1] = %p\n",&zippo[0][0],&zippo[0][1],&zippo[1][0],&zippo[1][1],&zippo[2][0],&zippo[2][1],&zippo[3][0],&zippo[3][1]);
return 0;

}

 

zippo 和 &zippo[0] 和 &zippo[0][0] 同一个地址 zippo[1][2] 因为C 不检查数组越界,所有zippo[1][2] 相当于 zipp0[2][0]

 

 

 

 

 

 

posted on 2014-03-12 09:58  loong qiang  阅读(209)  评论(0编辑  收藏  举报