Hi All,
I am C newbie ,my question is How Swap two variables with out third variable ?
and also i am looking for the online resources on Exercises for C programming .
Kanthi
Printable View
Hi All,
I am C newbie ,my question is How Swap two variables with out third variable ?
and also i am looking for the online resources on Exercises for C programming .
Kanthi
Do a web search for xor swap.
Hi Kanthi,
Swapping 2 variables is possible as follows:
x = x + yy = x - yx = x - y
Although this way doesn't require a third variable, but it is not simple to understand. So I think it is not good to use this way.
K.n.i.g.h.t
Please stop colouring your posts and centering all your text.
Not to mention the fact that your solution breaks down if arithmetic overflow or underflow happens.
Check the replies of those who have a clue here
http://cboard.cprogramming.com/showt...swap+variables
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages.