Domanda di colloquio di Northrop Grumman

How do you swap variables without using a temporary variable? Assume the variables are always integers.

Risposte di colloquio

Anonimo

26 set 2010

Shouldn't the last line be b = b - a;

5

Anonimo

20 set 2010

// Example, a = 4, b = 3; void swap (int a, int b) { b = a + b; // b = 7 a = b - a; // a = 3 b = b - b; // b = 4 }