TITLE: Lvalues and rvalues PROBLEM: sdoki@owl.WPI.EDU (Suresh Doki) What is an lvalue? What is an rvalue? RESPONSE: maxtal@physics.su.OZ.AU (John Max Skaller), 6 Feb 95 An lvalue is an expression which has two meanings: the address of an object and the value contained in the object. An rvalue has only one meaning: a value independent of any object. In ISO C, there are only lvalues and non-lvalues. The ISO C Standard defines which expressions are lvalues and which not. For example: int n; char buf[3]; buf[n]++; n is an lvalue (indeed, a variable) buf[n] is also an lvalue buf[n]++ isn't an lvalue Some operator require lvalues: = (on the LHS), ++, unary &. In C++ it is more complicated, rvalues of class type always denote objects -- temporary objects. This is because calling a member function requires a "this" pointer, which has to point to an actual object. Note that some expressions ISO C denotes non-lvalues are lvalues in C++. And note that the rules for when an lvalue is required by an operator ONLY apply to built-in operators and NOT compiler generated assignments: struct complex { double x; double y; }; complex sin(complex); complex z; sin(z)=sin(z); // error in ISO C, OK in C++ Since the "l" in "lvalue" came from the "L" in "Left Hand Side" of an assignment (and "r" from "Right Hand Side"), you might think the notion of lvalue in C++ is a bit weird. And you'd be right.