// // Filename: pgm3_6a.cpp // // Description: Demo program, References versus Pass by Value #1 // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 03/17/98 // Last Modified: 03/17/98 // // Name: N/A // #include void passByReference( int & choice ); void passByValue( int choice ); main() { int choice = -1; cout << "**** PASSING BY VALUE ****\n"; cout << "before 'passByValue()', choice is " << choice << endl; passByValue( choice ); cout << "after 'passByValue()', choice is " << choice << endl << endl; cout << "**** PASSING BY REFERENCE ****\n"; choice = -1; cout << "before 'passByReference()', choice is " << choice << endl; passByReference( choice ); cout << "after 'passByReference()', choice is " << choice << endl; return 0; } // pass by reference method void passByReference( int & x ) { cout << "\tinside 'passByReference()' ...\n"; cout << "\t x = " << x << endl; x += 10; cout << "\t x = " << x << endl; } // return value method void passByValue( int x ) { cout << "\tinside 'passByValue()' ...\n"; cout << "\t x = " << x << endl; x +=10; cout << "\t x = " << x << endl; }