Interview Question

Software Engineer New Grad Interview

-Singapore

Visa Inc.

How to swap two variables without a temp

AnswerAdd Tags

Interview Answers

3 Answers

2

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

Tony on

2

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

Anonymous on

0

What if the variable is big. like the max value of an integer. How do we do this without changing it to long (which is easy but obviously not the solution) use bitwise operations. a=3 b=4 a = a xor b xor a b = a xor b xor b

sandy on

Add Answers or Comments

To comment on this, Sign In or Sign Up.