C Program to Swap two Variables Without Using Third Variable.

Write a  C program to swap two variables without using the third variable.

Consider we have two variables a and b containing some number. We are asked to swap the values without using a third variable. For example, if in your C program you have taken two variables a and b where a = 10 and b = 20, after swapping it will become  a =20 and b = 10.

Here is the source code of the C program Swap two variables without Using the third variable. The C program is successfully compiled.

C Programming code :



Void main()


int a=10,b=20;


Printf(“before swapping a=%d \t b=%d”,a,b);




Printf(“after swapping”);

Printf(“A=%d \t B=%d”,a,b);