1// function definition to swap the values.
2void swap(int &x, int &y) {
3 int temp;
4 temp = x; /* save the value at address x */
5 x = y; /* put y into x */
6 y = temp; /* put x into y */
7
8 return;
9}
1#include <iostream>
2using namespace std;
3
4// function declaration
5void swap(int &x, int &y);
6
7int main () {
8 // local variable declaration:
9 int a = 100;
10 int b = 200;
11
12 cout << "Before swap, value of a :" << a << endl;
13 cout << "Before swap, value of b :" << b << endl;
14
15 /* calling a function to swap the values using variable reference.*/
16 swap(a, b);
17
18 cout << "After swap, value of a :" << a << endl;
19 cout << "After swap, value of b :" << b << endl;
20
21 return 0;
22}