Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Swap variable without arithmatic.. (http://www.go4expert.com/forums/swap-variable-arithmatic-t1369/)

vatsa_mitr 10Sep2006 13:13

Swap variable without arithmatic..
Hi all,
It might b an old question but how can i swap two variables without applying any arithmatic operation...

shabbir 10Sep2006 16:22

Re: Swap variable without arithmatic..
This can be done by applying any 2 operations that are are opposite to each other in nature like + and - * and /. The above are arithmetic operations and so if you cant use them you need to be doing either shifting or using the & / | to achieve the same


a = a OP1 b
b = a OP2 b
a = a OP2 b

OP1 and OP2 are opposite operations but I am not sure you can use the << and >> as there you loose one bit so you should be going with boolean operation.

All times are GMT +5.5. The time now is 05:46.