Write a program to swap two variable without using third variable and arthematic operator.

We can use bitwise operator for this.

Program:

 
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
    int a = 10; 
    int b =1000; 
    std::cout << "Before change:";
    std::cout << "\nA : "  <<  a; 
    std::cout << "\nB : " << b; 

    a = a ^ b; 
    b = a ^ b; 
    a = a ^ b;

    std::cout << "\n\nAfter change:";
    std::cout << "\nA : " << a; 
    std::cout << "\nB : " << b; 

    return 0;
}
Author: Hrishikesh Mishra