取消引用指针并存储对指向数据的引用,然后获取引用地址并对其执行指针运算。 C++

Dereferencing pointer and storing reference to the pointed data, then getting address of reference and performing pointer arithmetic on it. c++

为了制作图表(我自己的,以理解pointers/pointers-to-pointers/arrays)超出了这个问题的范围,我想知道是否足以假设以下内容:

int *intptr = new int[10]{0};
int &intref = *intptr;
int thirdInt = *((&intref)+2);//is this defined behavior and always equivalent to intptr[2]?????
delete [] intptr;

正如代码中唯一的注释所问:此代码是否调用了未定义的行为或未按注释预期的那样工作?

then getting address of reference

澄清这一点:“获取引用地址”是不可能的。当您在引用上应用 addressof 运算符时,您将获得所引用对象的地址。

this code invoke undefined behavior

没有

always equivalent to intptr[2]?????

是的(除非 class 类型对运算符 & 进行了奇怪的重载,但它们几乎不应该被使用)。