Intel Corporation interview question

How can you exchange the value of two variables without using a third variable?

Interview Answers

Anonymous

22 Mar 2011

x = x + y y = x - y x = x - y

9

Anonymous

6 Apr 2015

int Val1 = 5; int Val2 = 10; Val1 ^= Val2; Val2 ^= Val1; Val1 ^= Val2;