Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,072 software developers and data experts.

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.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.