markdown guide
 

While it does have some educational value to show that this is possible, this method has two issues:

  • Both a = a + b and a = a - b can cause an overflow.

  • I can't imagine many situations where saving a few bytes really makes up for the loss in readability.

 

It also works with XOR (avoiding the overflow problem):

a = a ^ b
b = a ^ b
a = a ^ b
 
 
Classic DEV Post from Mar 2

Which game are you playing right now?

What game are you playing right now? Do you have any favourites from your childhood that you reminisce about?

Programmer Rushikesh profile image