6 Years
Discussion Span
Last Post by Banfa

The standard splits all expressions into 2 broad categories, lvalue and rvalue. The actual definition with-in the standard is rather involved but a simplistic rule of thumb is that an lvalue is an expression that results in a modifiable value where as an rvalue doesn't. Any lvalue can be converted to an rvalue but rvalues can not be converted to lvalues.

l and r stand for left and right colloquially and refer to where the expression can appear in relation to the assignment operator.

lvalue = rvalue - good
rvalue = rvalue - bad

You can assign to an lvalue because it is modifiable, you can not assign to an rvalue because it is not modifiable. Not that you can only assign from an rvalue but because all lvalues can be converted to rvalues that is not an issue. int array[5]; declares an array, and NOT a pointer. An array is an rvalue (where as a pointer is an lvalue) and can not be assigned to. This is one of the differences between arrays and pointers. Because an array is an rvalue array++; produces an error because the ++ operator requires an lvalue.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.