#include using namespace std; // instead of "pass-by-value," let's change // this to "pass-by-reference" // by adding the "&" to each variable, the // variables a and b refer back to x and y void swap( int & a, int & b ) { // swap values of a and b: int temp = a; a = b; b = temp; cout << "a is " << a << " and b is " << b << endl; // no need for return at the end! return; // <== this is an OPTIONAL exit-point } // the swap() function has "void" as its return type, // which means that no value is returned // functions return either 0 or 1 result // if we want to "return" 2 or more values, use // the pass-by-reference mechanism int main() { int x = 5, y = 12; swap( x, y ); cout << "x is " << x << " and y is " << y << endl; return 0; }