/* This program illustrates call be reference. The Swap function takes 2 references to integers as parameters and swaps their values. Since they are references to variables in main, the corresponding variables in main are also changed. */ #include void Swap(int &, int &); /* Swap takes 2 integer references as parameters */ main() { int a, b, c; a = 3; b = 7; c = 13; Swap(a, b); /* this will set a to 7 and b to 3 */ cout << a << " " << b << "\n"; /* should print 7 3 */ Swap(b, c); /* this will set b to 13 and c to 3 */ cout << b << " " << c << "\n"; /* should print 13 3 */ } /* x and y are references to the corresponding variables in the call. Since they are refernces, changing x and y changes those corresponding variables. */ void Swap(int & x, int & y) { int temp; /* temporary storage to help with swap */ temp = x; /* store x in temp for now */ x = y; /* move y into x */ y = temp; /* move stored value of x into y */ return; }