Value categories: what can you point at?
Learn
Every expression in C++ has a value category. The textbook taxonomy (lvalue, prvalue, xvalue) sounds abstract, but there is one operational test that cuts through it: can you take the address of the result? If &expr is legal, the expression is an lvalue — it names a durable object with storage. If not, it is an rvalue — a value with no address you can hold onto.
int x = 5;
x // lvalue — &x is fine, x has storage
5 // prvalue — &5 is nonsense, it is just a value
x + 1 // prvalue — the + makes a temporary, no address Start with the discrimination itself. Which of these names something you could point at?
In int x = 5; int& r = x;, which expression below is an lvalue?
Now feel the consequence. The address-of operator is not just a test for lvalue-ness — it is the test, enforced by the compiler.
Does this compile? If not, why? Predict before revealing.
int a = 3, b = 4;
int* p = &(a + b);
std::cout << *p;
That distinction is the whole reason move semantics exists: an rvalue is a temporary about to die, so it is safe to steal from. The next skill builds directly on this.