/** * swap.cpp * 19-mar-2007/sklar * * demonstrates the use of functions that use reference parameters * see chapter 5 in the jones/harrow textbook * */ #include using namespace std; // Function prototypes void swap( int &a, int &b ); void notswap( int a, int b ); // Main program int main() { int x = 5; int y = 7; cout << "Before swap: x = " << x << " y = " << y << endl; swap( x, y ); cout << "after swap: x = " << x << " y = " << y << endl; } // Declare function swap(), using reference parameters // This one swaps the variable values. void swap( int &a, int &b ) { int tmp; tmp = a; a = b; b = tmp; return; } // Declare function notswap() // This does not swap the values. void notswap( int a, int b ) { int tmp; tmp = a; a = b; b = tmp; return; }