Intel Corporation Interview Question: How can you exchange the valu... | Glassdoor

Interview Question

Software Engineer Interview Santa Clara, CA

How can you exchange the value of two variables without

  using a third variable?

Interview Answer

3 Answers


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

Interview Candidate on Mar 22, 2011

This post has been removed.
Please see our Community Guidelines or Terms of Service for more information.


int Val1 = 5;
int Val2 = 10;

Val1 ^= Val2;
Val2 ^= Val1;
Val1 ^= Val2;

Anonymous on Apr 6, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.