/* Pass-by-reference can lead to aliasing * aliasing is when you can use two names to refer to the same location * in memory. * The output in this example is predictable, so, in that sense, it isn't a problem. * But it does mean you need to be careful when you call functions with * pass-by-reference. You need to know exactly what you are doing. */ #include using namespace std; int global = 1; int open_to_problems (int &a, int &b) { a = a + global; b = b + global; return 0; } int main () { int x = 10, y = 20; cout << "Before open_to_problems, x = " << x << ", y = " << y << endl; open_to_problems( x, y ); cout << "After open_to_problems, x = " << x << ", y = " << y << endl; cout << "Before open_to_problems, x = " << x << endl; open_to_problems( x, x ); cout << "After open_to_problems, x = " << x << endl; cout << "Before open_to_problems, x = " << x << endl; open_to_problems( global, x ); cout << "After open_to_problems, x = " << x << endl; return 0; }