// Swap in c++ // Compile with g++ -o swaptest swaptest.cpp #include using namespace std; // Pass the params by reference void swap(int &x, int &y) { int t = x; // Automatic dereference x = y; y = t; } int main() { cout << "C++ by reference" << endl; int a = 1; int b = 2; cout << a << b << endl; swap(a, b); // Address of param is passed cout << a << b << endl; }