Swap two variable without any 3rd variable.

To swap two variables without using arithmetic operators, you can use the XOR operator.
There are 3 ways you can do this ,

#1

a ^= b ^= a ^= b;

#2
a = a ^ b;
b = a ^ b;
a = a ^ b;
#3
a = a + b(b=a);

Leave a Reply

Your email address will not be published. Required fields are marked *