Tuesday, 31 January 2012

Scary trick ( swaping without declaring third variable )

  1. Initialize two integers a and b with the values of your desire
  2. a=a+b;
  3. b=a-b;
  4. a=a-b;
  5. 2nd, 3rd and 4th steps will swap the values of a and b. value of a will be shifted to b and value of b will be shifted to a. Enjoy it.

No comments:

Post a Comment