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;