C program to swap two numbers using XOR operator

Previous
Next
#include <stdio.h>
int main()
{
	int x, y;
	
	printf("Enter two numbers: ");
	scanf("%d%d", &x, &y);
	
	printf("Before swap = %d , %d\n", x, y);
	x ^= y;
	y ^= x;
	x ^= y;
	printf("After swap = %d , %d\n", x, y);
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form