//c++ program
#include
#include
void main()
{
printf("\nEnter two numbers");
int a,b;
cin>>a>>b;
a^=b^=a^=b; // interchanging variables without using temp.
// beauty is, it in "single line"
printf("\n\n%d %d",a,b);
}
2007-02-14 22:17:27
·
answer #1
·
answered by KillingJoke 3
·
1⤊
0⤋
NOTE: the XOR swap technique only works with integer types (byte, char, int, long)! This will not work with float or double types.
2007-02-15 02:05:44
·
answer #2
·
answered by Pfo 7
·
0⤊
0⤋
add the two variables, then subtract to swap.
a = a+ b;
b= a-b; //which is= a+b-b, that gives the value of a
a= a-b; // which is= a-a-b, that produces the value of b
2007-02-14 22:29:28
·
answer #3
·
answered by nikki 3
·
1⤊
1⤋
this is how to swap them simply, if you want more information please contact me?!
you can apply it on any language?!
x = x xor y
y = x xor y
x = x xor y
2007-02-14 22:20:40
·
answer #4
·
answered by Wish Master 5
·
1⤊
0⤋
int a,b
a=a+b
b=a-b
a=a-b
2007-02-15 04:40:08
·
answer #5
·
answered by Rajesh 2
·
0⤊
0⤋
80x86 assembly:
swap eax,ebx
Tada!
2007-02-14 22:12:39
·
answer #6
·
answered by Maniaca Esoterica 3
·
0⤊
1⤋