// Zig Herzog // Oct. 23, 2007 // Examples of passing one or multiple values back and forth using // the method "pass-by-reference" // If you run the program as shown below the cout statement will produce // v1=10 // // If you omit the & sign in "void ex1 ( int& )" and in "void ex1 ( int& v1 )" // the program will still compile but the cout statement will produce : // v1=2 // // The task of example below could also have been accomplished using // the method passing by value because only a single value needed to // be returned to the calling function ( main() ). #include <iostream> using namespace std ; void ex1 ( int& ) ; // <<<< prototyping int main () { int v1=2 ; ex1 ( v1 ) ; // <<<<< call to function ex1() cout << "v1=" << v1 << endl ; } ////////////// Definition of function ex1() //////////////////////// void ex1 ( int& v1 ) { int factor = 5 ; // this variable is local to function ex1(). v1 = v1 * factor ; }