Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

is it possibe that interchange two no. using only two integer in c not in c++

Always use XOR operations. Let us assume that both a and b are integers and suppose maximum value that an integer can store be 1000. let a=500 and b=700 then the methods suggested above will fail to give the right answers. so the correct way is to use the XOR operations

int a, b; a= 5; b= 7; a= a+b; b=a-b; a=a-b; this will give the requied solution.. there are couple of more solutions to this.. the XOR suggested above is also correct.!! :)

Sign in to post your reply or Sign up for a free account.