3.1 In general

Out of the context of classes, references can be used in C++. Let us consider the following example:

int i;
int &j = i;

i = 23;
j = 0;
cout << i << endl;
cout << j << endl;

This code prints 0 twice! This is because j is a reference to i. This means j is an alias of the object that is also known as i. When j appears on the left hand side of the assignment operator, it specifies the storage of variable i.



Copyright © 2006-09-19 by Tak Auyeung