How to exchange two variables without using a third
Is it possible to exchage two variables without using temp?
(in C) how can it be done.....!!!!!!!!!! |
a,b be the two variables
(I) temp=a; a=b; b=temp; using an extra variable and with out using an extra variable (II) a=a+b; b=a-b; a=a-b; There r many ways 2 swap values of two variables Hope this helps :-) |
a^=b^=c^=a
but all these will work for integers only. when u say variable it has a larger context |
Quote:
This should work: Code:
a = a^b; |
All times are GMT -5. The time now is 09:51 AM. |