标签:io os ar div art c on amp r
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 */
标签:io os ar div art c on amp r
原文地址:http://www.cnblogs.com/gcczhongduan/p/4005325.html