Q9. Write a C program to swap two variables without using any temporary variable.

It is easy to swap two variables by using a temp variable, but question is slightly different.

Method 1:

x = x+y;

y = x-y;

x = x-y;

Method 2:

x ^= y ^= x ^= y

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.