xxxxxxxxxx
#include <iostream>
using namespace std;
int main(){
int A,B,l,n;
A=l;
B=n;
string "grelnandia";
std::string A=l, B=n;
std::cout<< "Value of A before swap function call = " << 'A' << std::endl;
std::cout<< "Value of B before swap function call = " << 'B' << std::endl;
std::swap( A, B );
std::cout<< "Value of A after swap function call = " << 'A' << std::endl;
std::cout<< "Value of B after swap function call = " << 'B' << std::endl;
return 0;
}
xxxxxxxxxx
int a{}, b{}, temp{};
cin >> a >> b;
//===================== METHOD-1
temp = a;
a = b;
b = temp;
//===================== METHOD-2 ( XOR ^ )
// example: a^b = 5^7
a = a ^ b; // 5^7
b = a ^ b; // 5 ^ 7 ^ 7 //5 ( 7 & 7 dismissed)
a = a ^ b; // 5 ^ 7 ^ 5 //7 ( 5 & 5 dismissed)
//===================== METHOD-3 ( swap() )
swap(a, b);
cout << "a " << a << endl;
cout << "b " << b << endl;
xxxxxxxxxx
Input : set1 = {1, 2, 3, 4}
set2 = {5, 6, 7, 8}
set1.swap(set2);
Output : set1 = {5, 6, 7, 8}
set2 = {1, 2, 3, 4}
Input : set1 = {'a', 'b', 'c', 'd'}
set2 = {'w', 'x', 'y', 'z'}
set1.swap(set2);
Output : set1 = {'w', 'x', 'y', 'z'}
set2 = {'a', 'b', 'c', 'd'}