The term rvalue refers to a data value that is stored at some address in memory. An rvalue is an expression that cannot have a value assigned to it. Both a literal constant and a variable can serve as an rvalue. When an lvalue appears in a context that requires an rvalue, the lvalue is implicitly converted to an rvalue. The reverse, however, is not true: an rvalue cannot be converted to an lvalue. Rvalues always have complete types or the void type.
C defines a function designator as an expression that has function type. A function designator is distinct from an object type or an lvalue. It can be the name of a function or the result of dereferencing a function pointer. The C language also differentiates between its treatment of a function pointer and an object pointer.
| Operator | Requirement |
|---|---|
| & (unary) | Operand must be an lvalue. |
| ++ -- | Operand must be an lvalue. This applies to both prefix and postfix forms. |
| = += -= *= %= <<= >>= &= ‸= |= | Left operand must be an lvalue. |
For example, all assignment operators evaluate their right operand and assign that value to their left operand. The left operand must be a modifiable lvalue or a reference to a modifiable object.
| Expression | Lvalue |
|---|---|
| x = 42 | x |
| *ptr = newvalue | *ptr |
| a++ | a |
When
compiled with the GNU C language extensions enabled, compound expressions,
conditional expressions, and casts are allowed as lvalues, provided
that their operands are lvalues.
(x + 1, y) *= 42; x + 1, (y *=42);
&(x + 1, y); x + 1, &y;
A conditional expression can be a
valid lvalue if its type is not void and both of its branches for
true and false are valid lvalues. Casts are valid lvalues if the operand
is an lvalue. The primary restriction is that you cannot take the
address of an lvalue cast.