hi all!!
i am a newbie in this forum.
can u solve me the problem of interchanging/swapping the value of two varibles without using the third variable...
thanks..
Last edited by WolfPack; Sep 11th, 2007 at 4:52 am. Reason: CHANGED ALL UPPERCASE TO LOWERCASE.
Yes you can http://c-faq.com/expr/xorswapexpr.html
But that is a dumb trick which ceased to be of any importance when we came down from the trees and started using high level programming languages.
- it would be OK on unsigned types.
- it would be liable to arithmetic overflow on signed types.
- for floating point types, expect both to become corrupted, especially if values differ greatly in magnitude
- utterly hopeless as an approach for any other type.
I would really suggest to use the temp variable to swap two values. Cos the swapping variables without third variable such as using the arithmetic operators. This would really very help only when you wanted to swap unsigned integers. Apart from that it is not a recommended at all. If anything other unsigned integers you need to use the temp variable to swap. But in over all the latter would be efficient way of doing it.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.