Bank of America interview question

Swap two numbers while not using the temp variable.

Interview Answers

Anonymous

Sep 27, 2013

a = a+b; b = a -b; a= a- b;

7

Anonymous

Mar 10, 2013

using the XOR operator

3

Anonymous

Feb 4, 2015

a = a ^ b b = a ^ b a = a ^ b This will avoid over flows which might come in addition steps