KPIT Technologies interview question

I was asked to exchange two values in c code without using temporary variable.

Interview Answer

Anonymous

5 Sept 2018

Its Simple,Just Preform Addition And Subtraction Operation. Consider We Have Variable A And B 1) Add A and B And Store The Result In A. (A=A+B;) 2)Now Subtract B From Modified A And Store Result in B. (B=A-B;) 3)Now Subtract A From Modified B And Store The Result In A. (A=A-B;) And Values Are Swapped