Springboard Pillow
Paddling in the murky bits of the byte stream
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:
http://wiki.answers.com/Q/How_do_you_write_a_program_in_C_to_swap_two_variables_without_using_the_third_one
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
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment