标签:os io ar amp size har print 数组
int a[3];
a 和 &a 的地址一样的。
a+1 == a + 1*sizeof(int);跳跃是一个数组元素大小
&a+1 == a + 3*sizeof(int);跳跃是整个数组大小
#include <stdio.h> int main() { char * a[] = {"hello","the","world"}; char ** pa = a; pa ++; /* 获取数组中第二个元素 */ printf("*pa = %s\n",*pa); printf("*(a+1) = %s\n",*(a+1)); int b[] = {1,2,3}; int * pb = b; /* 获取数组中最后一个元素 */ printf("*((int *)(&b +1)-1) = %d\n",*((int *)(&b +1)-1)); printf("*((int *)((&b +1)-1) = %d\n",*((int *)((&b +1)-1))); printf("*((char **)(&a+1)-1) = %s\n",*((char **)(&a+1)-1)); /* 地址一样 */ printf("b = 0x%0X\n",b); printf("&b = 0x%0X\n",&b); } /* [root@localhost test_class]# ./a.out *pa = the *(a+1) = the *((int *)(&b +1)-1) = 3 *((int *)((&b +1)-1) = 1 *((char **)(&a+1)-1) = world b = 0xBFC556B0 &b = 0xBFC556B0 */
int a[3];中a+1与&a+1区别 -- C,布布扣,bubuko.com
标签:os io ar amp size har print 数组
原文地址:http://blog.csdn.net/cy_cai/article/details/38293805