#include // C++ can pass arguments are references // by value int square(int x) { return x * x; } // swap by value (passing pointers) void swap(int *x, int *y) { int temp = *x; *x = *y; *y = temp; } // Swap by reference - function overload void swap(int& x, int& y) { int temp = x; x = y; y = temp; } int main(void) { int a = 9, b; b = square(a); std::cout << "Square of a: " << b << std::endl; std::cout << "A: " << a << " B: " << b << std::endl; swap(&a, &b); std::cout << "Swapping by addr value:" << std::endl; std::cout << "New A: " << a << " New B: " << b << std::endl; swap(a, b); std::cout << "Swapping by reference:" << std::endl; std::cout << "New A: " << a << " New B: " << b << std::endl; return 0; }