1#include <iostream>
2using namespace std;
3
4// Function prototype
5void swap(int&, int&);
6
7int main()
8{
9 int a = 1, b = 2;
10 cout << "Before swapping" << endl;
11 cout << "a = " << a << endl;
12 cout << "b = " << b << endl;
13
14 swap(a, b);
15
16 cout << "\nAfter swapping" << endl;
17 cout << "a = " << a << endl;
18 cout << "b = " << b << endl;
19
20 return 0;
21}
22
23void swap(int& n1, int& n2) {
24 int temp;
25 temp = n1;
26 n1 = n2;
27 n2 = temp;
28}
1#include <iostream>
2using namespace std;
3
4// Function prototype
5void swap(int*, int*);
6
7int main()
8{
9 int a = 1, b = 2;
10 cout << "Before swapping" << endl;
11 cout << "a = " << a << endl;
12 cout << "b = " << b << endl;
13
14 swap(&a, &b);
15
16 cout << "\nAfter swapping" << endl;
17 cout << "a = " << a << endl;
18 cout << "b = " << b << endl;
19 return 0;
20}
21
22void swap(int* n1, int* n2) {
23 int temp;
24 temp = *n1;
25 *n1 = *n2;
26 *n2 = temp;
27}