Swapping of Two Numbers in C: Without Using Third Variable Pointers Functions (Call by Reference) XOR
Swapping of Two Numbers in C: Without Using Third Variable Pointers Functions (Call by Reference) XOR
pointers, functions (Call by reference) and using bitwise XOR operator, swapping means
interchanging. For example if in your c program you have taken two variable a and b where a = 4
and b = 5, then before swapping a = 4, b = 5 after swapping a = 5, b = 4
In our c program to swap numbers we will use a temp variable to swap two numbers.
int n, reverse = 0;
printf("Enter a number to reverse\n");
scanf("%d",&n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is = %d\n", reverse);
return 0;