My confusion:
Since both the pointers and references use the symbol &, and in pointers & symbol is usually interpreted as "the address of ...", I wonder whether it should be interpreted the same in references.
My theory:
When & sign appears on the right hand side of =, it can be interpreted as "the address of".
When & sign appears on the left hand side of =, it should be associated with references and CAN'T be directly interpreted as "the address of".
My proof:
&in pointers:
int a = 1;
int *p = &a;
The value of pointer variable p is the address of variable a.
In other words, p is a pointer pointing to variable a.
&in references:
int a = 1;
int & b = a;
b is a reference to a.
In other words, the address of reference variable b is the same as the address of variable a.
But the code itself wouldn't be appropriate to directly interpreted it as "the address of reference variable b is the address of variable a", because otherwise then the code should instead be
int a = 1;
int & b = &a;
, and that is incorrect according to C++ syntax.
Error message:
error: cannot bind rvalue '(int)(& a)' to 'int&'
Thanks for replies in advance!