Lecture 2 - Slide 15 : 29
References - Examples

Here we show a number of examples that illustrate various aspects of references

"The absence of const in a declaration of a reference (argument) is taken as a statement of intent to modify the variable"

ref-basic.cc
A variable becomes a reference to another variable.
ref-basic-2.cc
No operator operates on a reference as such.
min-max.cc
A typical use of references: A number of results passed back from vector_min_max via references.
ref1-bad.cc
A function that attempts to return references to local variables.
ref1-better.cc
Ditto - handling the problem by making the local variable static.
ref1.cc
A function with reference parameters and reference return type.
ref-fields.cc
Convenient references to long/deep fields.
The The C++ Prog. Lang. (4. edition) example on page 192-193 is also very illustrative
Go to exercise
Another example/exercise with C++ references
Go to exercise
Pointers in combination with references