references/ref-basic.cc - A variable becomes a reference to another variable. | Lecture 2 - slide 15 : 29 Program 1 |
// Very simple example - illustrates an alias e of d in a function f. #include <iostream> #include <string> using namespace std; double f(double di = 6.0){ double d = di, // d initialized to the value of the parameter di &e = d; // e is an alias to d e += 7.0; // increasing e, and hereby d, by 7 return d; } int main(){ cout << f() << endl; // 13 cout << f(8) << endl; // 15 }