employer cover photo
employer logo
employer logo

Tata Consultancy Services

Part of Tata Group

Engaged employer

Tata Consultancy Services interview question

How will you swap two numbers without using a temp

Interview Answer

Anonymous

1 Mar 2013

int a = 5; int b = 10; a = a + b; // i.e. a = 5 + 10 = 15; b = a - b; // i.e. b = 15 - 10 = 5; a = a - b; // i.e. a = 15 - 5 = 10; Final Answer is a = 10 and b = 5.

1