Pergunta de entrevista da empresa Yahoo

How do you switch values of variables A and B without using a third variable for storage?

Resposta da entrevista

Sigiloso

14 de jul. de 2013

b = a + b a = b - a b = b - a If we have a = 3 and b = 5 we have: b = 3 + 5 = 8 a = b - a = 8 - 3 = 5 b = b - a = 8 - 5 = 3

1