// Project File reference.cpp #include using namespace std; int main() { void f(int, int&); int& g(int&); int x = 3, y = 5; cout << x << " " << y << endl; f(x, y); cout << x << " " << y << endl; x = g(x); cout << x << " " << y << endl; return EXIT_SUCCESS; } void f(int a, int &b) { a += 2; b += 2; } int& g(int &a) { a += 9; return a; } // The preceding function avoids making a copy // of a when it is passed in and avoids making // a copy of the value of a when it is returned. // This is especially useful when an input file // object (ostream) is passed in and returned. // Because the copy constructor for ostream is // private, a copy cannot be made, so references // are the only possibility. // Output: // 3 5 // 13 13 // 13 7 // 22 7