#include using namespace std; // pass by value (only copy swapped) void mySwap(int a, int b){ int t = a; a = b; b = t; cout << a << " " << b << endl; } // pass by reference (data in main swapped) void mySwapR(int &a, int &b){ int t = a; a = b; b = t; cout << a << " " << b << endl; } // pass by pointer (data in main swapped) void mySwapP(int *a, int *b){ int t = *a; *a = *b; *b = t; cout << *a << " " << *b << endl; } void main(){ int x = 1, y = 17; double d = 3.14159; double &rd = d; rd = -4.789; cout << &rd << " " << &d << endl; cout << d << endl; mySwap(x, y); cout << x << " " << y << endl; mySwapP(&x, &y); cout << x << " " << y << endl; mySwapR(x, y); cout << x << " " << y << endl; }