1int a{}, b{}, temp{};
2cin >> a >> b;
3
4 //===================== METHOD-1
5 temp = a;
6 a = b;
7 b = temp;
8
9 //===================== METHOD-2 ( XOR ^ )
10 // example: a^b = 5^7
11 a = a ^ b; // 5^7
12 b = a ^ b; // 5 ^ 7 ^ 7 //5 ( 7 & 7 dismissed)
13 a = a ^ b; // 5 ^ 7 ^ 5 //7 ( 5 & 5 dismissed)
14
15 //===================== METHOD-3 ( swap() )
16 swap(a, b);
17
18 cout << "a " << a << endl;
19 cout << "b " << b << endl;
20
1Return Value: The function does not return anything, it swaps the values of the two variables
1int main()
2{
3 int a = 5;
4 int b = 10;
5
6 swap(a, b);
7
8 cout << "a = " << a << endl;
9 cout << "b = " << b << endl;
10}