GeekInterview | Geeks Forum | Online Quiz | Learning Center | Privacy | Terms and Conditions | Contact
GeekInterview Code Base
Code Snippets Login Register

Swaping of two No.s

Swaping of two No.s without 3rd variable
12 September, 2007
prabha
0
N/A

Swaping of two No.s without 3rd variable

 

Comments [ Leave Comment ]

Posted by babu_krishi at 09 October, 2007
Great and logically correct
Posted by jagatsastry at 22 October, 2007
1) int main() invokes undefined behavior.
2) The method poses overflow problems, so swapping two numbers which are greater than half of the limited int size gives incorrect result.
A better method for swapping two integers a and b is
a^=b;
b^=a;
a^=b;

 

Tips [ Leave Tip ]

No tips added yet. Be the first one to share tip.

 

Reviews [ Leave Review ]

No reviews added yet. Be the first one to review.

 

Tags

code

 

Related Categories

DB2 » Database » C/C++
SQL Server » Database » C/C++
Oracle » Database » C/C++
MYSQL » Database » C/C++
Code Samples » C/C++
Copyright @GeekInterview.com