“*& var”会返回存储在“var”中的值吗?

时间:2014-07-10 05:22:07

标签: c++ pointers reference dereference

如果:

int var = 0;
&var;   //--> returns the address of "var"

int *p = &var;
*p;   //--> returns the value pointed to by "p", the value stored in "var"

然后不应该(但多余):

*&var;  //--> returns the value stored in "var"
*var;   //--> throw an error (or return the value stored in "var")?

我现在无法编译C ++代码,但我想弄清楚这些运算符。

1 个答案:

答案 0 :(得分:4)

*&var;  //--> returns the value stored in "var"

是的,&var是一个指向var的指针,然后*&varvar相同。

*var;   //--> throw an error (or return the value stored in "var")?

这不会编译,因为您不能尊重int