C Program to swap two variables by performing xor operation
In this program, two integers are swapped by performing an 'ex-or' operation, which swaps two numbers.
Program
#include<stdio.h>
void main()
{
int a, b;
printf("Enter two numbers\n");
scanf("%d %d", &a, &b);
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("Swapped numbers are:\n");
printf("a:\t%d\nb:\t%d\n", a, b);
}
Output
Enter two numbers
234
300
Swapped numbers are:
a: 300
b: 234