Using - C++
#include<iostream>
using namespace std;
class Swapper {
public:
void Swap(int *a, int *b);
};
void Swapper::Swap(int *a, int *b) {
*a += *b;
*b = *a - *b;
*a = *a - *b;
}
int main() {
int a, b;
Swapper object;
cout<< "Enter the value of a: ";
cin>> a;
cout<< "Enter the value of b: ";
cin>> b;
system("cls");
cout<< "Before Swapping: a = "<< a<< " & b = "<< b<< endl;
object.Swap(&a,&b);
cout<< "After Swapping : a = "<< a<< " & b = "<< b<< endl;
return 0;
}
OUTPUT
Enter the value of a: 100
Enter the value of b: 200
-------------------------------------------------
Before Swapping: a = 100 & b = 200
After Swapping : a = 200 & b = 100