#include using namespace std; /* Illustrates the difference between a value parameter and a reference parameter. */ int squareVal( int i ) // This function has its own local { // storage for its parameter, i. This storage is i *= i; // NOT accessible to any other function. return i; } int squareRef( int& i ) // This function shares the storage with { // the calling program for its parameter, i. i *= i; return i; } int main( ){ int j = 2; cout << "Initially, j == " << j << ".\n"; cout << "squareVal(j) == " << squareVal(j) << ".\n"; cout << "After the call to squareVal(), j == " << j << ".\n"; cout << "squareRef(j) == " << squareRef(j) << ".\n"; cout << "After the call to squareRef(), j == " << j << ".\n"; return 0; } /* Output: Initially, j == 2. squareVal(j) == 4. After the call to squareVal(), j == 2. squareRef(j) == 4. After the call to squareRef(), j == 4. */