Resorter Resorter - 7 months ago 53
C++ Question

C++ does reference return a lvalue or rvalue?

int a, b;

This simple code causes the following error when compiled.

error: lvalue required as left operand of assignment

is indeed on the left hand-side. So what does the error message exactly mean?


In this context & is the address-of operator. The value of &b is a pointer of type int *. It is a prvalue. This is unrelated to use of the & symbol in a declaration (where it means the declaration of a reference) -- symbols mean different things in declarators than they do in expressions.

You cannot change the address of a variable. Variables have the same address for their whole lifetime.