Colgate-Palmolive interview question

How do you swap two integer variables without creating a temporary variable?

Interview Answers

Anonymous

23 Sept 2017

int x = 10; int y = 12; x = x+y //x = 22, y = 12 y = x - y //x = 22, y = 10 x = x-y // x= 12, y=10

1

Anonymous

1 Feb 2019

In python: a, b = b, a