6.2.2. Passing Arguments by Reference
int n = 0, i = 42;int &r = n; // r is bound to n (i.e., r is another name for n)r = 42; // n is now 42r = i; // n now has the same value as ii = r; // i has the same value as n
Reference parameters exploit this behavior. They are often used to allow a function to change the value of one or more of its arguments.
As one example, we can rewrite our
reset program from the previous section to take a reference instead of a pointer: