Interview Question

Software Engineer Interview Santa Clara, CA

How can you exchange the value of two variables without

  using a third variable?
Answer

Interview Answer

3 Answers

7

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.

0

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.