I was searching for how to swap two numbers without temporary variable. Then I came across this blogpost.
He used xor operator to swap. I was amazed to see it.
Here is his program
Code:
#include<stdio.h>
int main(int argc, char const *argv[]){
int number1,number2;
printf("\nSwapping of two numbers in c\nEnter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("Number 1: %d\nNumber 2: %d",number1,number2);
//swapping
number1=number1^number2;
number2=number1^number2;
number1=number1^number2;
printf("\nAfter swapping");
printf("\nNumber 1: %d\nNumber 2: %d\n",number1,number2);
return 0;
}