0

:icon_smile:
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..

6
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by Salem
0

Ever hear of arithmetic overflow ?

- 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.

0

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.

ssharish

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.