GeeksforGeeks » Interview Questions
Swapping two nos without arithmetic and logical operators
(4 posts)-
Tis was asked for my frend in thought works interview..... How to swap two numbers without using a temporary variable, logical and arithmetic operators?
-
bitwise xor
-
yeah bitwise xor would do..this is the algorithm for your help..
swap(int x , int y)
{
x=x xor y;
y=x xor y;
x=x xor y;
} -
a=(a+b)-(b=a)
Reply
You must log in to post.