example5_lvalues_vs_rvalues.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <iostream>

int main() {
    int x = 10;         // 'x' is an lvalue
    int y = x + 5;      // 'x + 5' is an rvalue

    int* p1 = &x;       // OK: 'x' is an lvalue
    // int* p2 = &(x + 5); // Error: 'x + 5' is an rvalue, can't take its address

    y = 15;             // OK: 'y' is an lvalue

    return 0;
}
Back to lvalue