- int a[ ] ={1,2,3,4,5};
- int *p = (int*)(&a + 1);
- printf("%d \n %d \n",*(a + 1),*(p - 1));
- printf("-----------------------\n");
- printf("%p\n",a);
- printf("%p\n",&a);
- printf("%p\n",a+1);
- printf("%p\n",a+2);
- printf("%p\n",a+3);
- printf("%p\n",a+4);
- printf("%p\n",&a+1);
- printf("%p\n",p-1);
- printf("%p\n",p);
- printf("%lu\n",sizeof(int*));
- printf("%p\n",(int*)1);
复制代码
结果如下:2
5
-----------------------
0x7fff5fbff770
0x7fff5fbff770
0x7fff5fbff774
0x7fff5fbff778
0x7fff5fbff77c
0x7fff5fbff780
0x7fff5fbff784
0x7fff5fbff780
0x7fff5fbff784
8
0x1
Program ended with exit code: 0
&a+1越界了,*(a+1)是数组的第二个元素,跟指针p没有关系 |