Pergunta de entrevista da empresa Northrop Grumman

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

Respostas da entrevista

Sigiloso

26 de set. de 2010

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

5

Sigiloso

20 de set. de 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 }