Swap two variables without using temporary variable

© Parineeth M R

Question 48. Swap two variables without using a temporary variable


There are two ways to solve this problem. The first uses XOR and the second uses addition and subtraction. The XOR technique can be used for swapping any two variables whereas the addition and subtraction technique can only be used for numbers. The two techniques are described below