Intel Corporation Interview Question

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

Interview Answers

Anonymous

Mar 22, 2011

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

9

Anonymous

Apr 6, 2015

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