C/C++: Swap Two Value by XOR
Posted on May 9th, 2008 by hengdu
#include<stdio.h>
int
main()
{
int one=20;
int two=21;
one ^= two;
two ^= one;
one ^= two;
printf(“new one is:%d, new two is:%d\n”, one, two);
return 0;
}
#include<stdio.h>
int
main()
{
int one=20;
int two=21;
one ^= two;
two ^= one;
one ^= two;
printf(“new one is:%d, new two is:%d\n”, one, two);
return 0;
}
Discussion Area - Leave a Comment