指针 + 1
1. 32 位和 64 位程序指针是多少位 32位指针大小为4个字节,64位指针大小位8个字节 2. 指针加 1,是对该指针增加 1 个储存单位 “存储单位”,指的是指针指向的数据类型所占的内存的字节数。不同类型的指针加1后,增加的大小不同。 int main() { int a[] = {1, 2, 3, 4, 5}; // &a是数组指针,其类型为 int (*)[5],a是长度为5的int数组指针,所以要加 5*sizeof(int),所以ptr实际是a[5]; // &a+1不是首地址+1,系统会认为加一个a数组的偏移,是偏移了一个数组的大小(本例是5个int) // 但是prt与(&a+1)类型是不一样的(这点很重要,ptr指向的是整形),所以prt-1只会减去sizeof(int) int *ptr = (int*)(&a + 1); cout << *(a + 1) << endl; cout << *(ptr - 1) << endl; return 0; } 输出: 2 5 注: a,&a的地址是一样的,但意思不一样: a是数组首地址,也就是a[0]的地址,a+1是数组下一元素的地址,即a[1] &a是对象(整个数组作为一个对象)首地址,而&a+1是下一个对象的地址,即a[5].