Sunday, 15 April 2012

c++ - Swapping two variable value without using third variable -


One of the very difficult questions asked in an interview.

Swap values ​​of two variables like a = 10 and b = 15 .

To automatically swap two variable values, we need a 3G variable:

  temporary = a; A = b; B = temporary;  

Now it is necessary to swap values ​​of two variables without using 3 variables.

No comments:

Post a Comment