June 16, 2011

How to swap two variables, without using third variable ?

Swap two variables with out using third variable:
a=5,b=10
a=a+b;
b=a-b;
a=a-b;
-------
use xor to swap
a = a^b
b= a^b
a= a^b

-------
or
a=a*b;
b=a/b;
a=a/b;

No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts