2.13 lvalues and rvalues

An rvalue is the value of an expression, such as 2, or x + 3 , or (x + y) * (a - b) . rvalues are not storage space. Examples of rvalues are the numbers 0 and 1 in the following code fragment:

if (x > 0)
   {
     y += 1;
   }
x = *y;        /*  The value pointed to by y is assigned to x   */

The identifiers x and y are objects with allocated storage. The pointer to y holds an lvalue.

An lvalue is an expression that describes the location of an object used in the program. The location of the object is the object's lvalue, and the object's rvalue is the value stored at the location described by the lvalue. The following operators always produce lvalues:

[]
*
->

The dot operator ( . ) can, and usually does, produce an lvalue but it does not have to do so. For example, f().m is not an lvalue.

A modifiable lvalue is an lvalue that does not have array type, an incomplete type, a const -qualified type, or, if it is a structure or union, has no member with const -qualified type.


Previous Page | Next Page | Table of Contents | Index