1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Functions that return Lvalues

Lvalues are "things that can occur on the left-hand side of the assignment operator.'' References allow functions to return Lvalues:

int a[10];

int&foo( int i ) {
return a[i - 2000];
}

int main() {
foo(2004) = 7; }

// Sets a[4] = 7

This is also useful for overloading operators; operator= for type T would be of type T&.

22-Mar-98

Page 14

C201/TAM