Qualcomm interview question

Swap two numbers without using a temporary variable

Interview Answers

Anonymous

Jan 26, 2010

x = 10 y = 5 x = x+y // x = 15, y =5 y = x-y // x = 15 , y = 10 x = x-y // x = 15 - 10 = 5 , y = 10 another way, x = x^y y = x^y x = x^y

6

Anonymous

Jun 28, 2016

Shift register.

1

Anonymous

Nov 5, 2017

a = a ^ b; b = a ^ b; a = a ^ b;