Prudential Interview Question

How can you swap two integers without using a temporary value?

Interview Answer

Anonymous

Nov 25, 2024

int a = 5, b = 10; a = a + b; // a becomes 15 (5 + 10) b = a - b; // b becomes 5 (15 - 10) a = a - b; // a becomes 10 (15 - 5)