Difference between two seperate swaps
What are the advantages/disadvantages of XOR swap over using a temporary variable? I think it looks cleaner to use an XOR and also eliminates using an extra variable, however that's really not a big deal anyways with all the memory available. Why don't schools teach more about bitwise operators? Are they really that unimportant?
Code:
int main(void)
{
int x=5,y=12;
x^=y;
y^=x;
x^=y;
return 0;
}
Code:
int main(void)
{
int x=5,y=12, temp;
temp=x;
x=y;
y=x;
return 0;
}