#include using namespace std; /** * Swap two integer values passed in by value. * @param a the first value. * @param b the second value. */ void swap_by_value(int a, int b); /** * Swap two integer values passed in by reference. * @param a the first value. * @param b the second value. */ void swap_by_reference(int& a, int& b); int main() { int i = 1, j = 5; cout << "Before swap_by_value: i = " << i << ", j = " << j << endl; swap_by_value(i, j); cout << " After swap_by_value: i = " << i << ", j = " << j << endl; cout << endl; cout << "Before swap_by_reference: i = " << i << ", j = " << j << endl; swap_by_reference(i, j); cout << " After swap_by_reference: i = " << i << ", j = " << j << endl; } void swap_by_value(int a, int b) { int temp = a; a = b; b = temp; } void swap_by_reference(int& a, int& b) { int temp = a; a = b; b = temp; }