I have been asked a question to swap two numbers without using temporary variable. It was a easy to answer the question with the following answer.
swapping with temp variable
int a =10;
int b =20;
int temp = a;
a = b;
b = temp;
swapping without temp variable
int a =10;
int b =20;
a = a+b;
b = a-b;
a = a-b;
It works, But which is better in terms of performance? When it is only one time operation performance doesn't matter i think. But if i need to reverse a huge array of numbers using this swapping method or during a selection sort where swapping needed etc.., creating local variable is better or doing it with arithmetic operation?