0

Why can I not assign memory address of a variable to another memory address of a variable?

I am trying to assign a memory address of a variable to other variable's memory address. For example: int a; int &b=a;//I can do that. But I can't do that: int a; int b; &b=&a; Why can I not do that?

4th Oct 2017, 9:11 AM
Yusuf
Yusuf - avatar
2 Answers
+ 3
Because &b is not a variable. It's just like you can't assign to -x or to (2*a). You can store memory addresses in variables like int *b = &a;
4th Oct 2017, 9:33 AM
Schindlabua
Schindlabua - avatar
+ 10
In addition to Schindlabua's nice illustration, see this comprehensive article about "lvalue and rvalue". [https://eli.thegreenplace.net/2011/12/15/understanding-lvalues-and-rvalues-in-c-and-c#]
4th Oct 2017, 10:22 AM
Babak
Babak - avatar