Tuesday, July 21, 2009

Swapping Two Numeric Variables In Only Three Instructions

Having done this in the past, needing it again and finding this page:
I've found that two numerics can be swapped quite easily without the use of a third variable:

a = a + b
b = a - b
a = a - b

Neat.

No comments:

Post a Comment