example1_glvalues.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int getValue() {
    int a = 10;
    return a;
}

int main() {
    int x = 5;          // 'x' is an lvalue and also a glvalue
    int* p = &x;        // OK: Can take the address of an lvalue

    x = 10;             // OK: 'x' is modifiable

    int&& y = getValue();  // 'getValue()' is a prvalue, 'y' is an xvalue
    int* q = &y;           // OK: Can take the address of an xvalue

    y = 15;             // OK: 'y' is modifiable

    return 0;
}
Back to glvalue