To swap two variables, use the bitwise XOR operator. When two integers x and y are XORed, the result is a number with all bits set to 1 wherever the bits of x and y differ. For instance, the XOR of 10 (in Binary 1010) and 5 (in Binary 0101) is 1111, while the XOR of 7 (0111) and 5 (0101) is 1111. (0010).
This is a question that most of us have asked at some point in our lives. However, it is not easy to answer because there are so many possibilities. C language uses the two-operand instruction for swapping the two numbers in the expression on the left and right side of the equals sign. This is called a swap instruction. When C language executes an assignment statement, it first stores an old value in memory and then assigns a new value to the old memory location. This process is called de-referencing.
If you have a=1 and b=2, you are swapping. If you do a=2 and b=1 in any way, this number will be swapped. You can swap numbers with or without the use of variables!
Swapping two numbers in C can have consequences on the functionality of the program. For example, if you swap two numbers, it can cause an overflow error or undefined behavior.