Resorter Resorter - 1 year ago 105
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download