Domanda di colloquio di Yahoo

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

Risposta di colloquio

Anonimo

14 lug 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