C Programming Code Examples C > Miscellaneous Code Examples C Program to Swap two numbers using XOR Operator C Program to Swap two numbers using XOR Operator Generally Swaping two number requires three variables , Let's Take look at Procedure of swaping two Number For Swaping Two numbers following procedure is used - Let x = 12 and y = 9 [ For our sake and simplicity consider number is of 4 bits ] #include<stdio.h> int main() { int j1, j2; printf("\nEnter First Number : "); scanf("%d", &j1); printf("\nEnter Second Number : "); scanf("%d", &j2); j1 = j1 ^ j2; j2 = j1 ^ j2; j1 = j1 ^ j2; printf("\n Numbers after Exchange : "); printf("\n j1 = %d and j2 = %d", j1, j2); return(0); }