Swapping Function
/* * Here is one nice use of reference parameters. */ #include <iostream> using namespace std; // This function exchanges its parameters. (And // it's real hard to write in Java.) void swap(int &a, int &b) { int t = a; a = b; b = t; } int main() { int x = 12, y = 71; cout << "x = " << x << ", y = " << y << endl; swap(x,y); cout << "x = " << x << ", y = " << y << endl; }

One use of reference parameters.