A balance of the month swap
t = a; a = b; b = t; // t is a third integer variable (swap variable) But here's a way without a swap variable, given as as a macro in C: #define SWAP(a,b) { if (a!=b) { a^=b; b^=a; a^=b; }} // Swap macro by XOR Once you define it, you can say swap(x,y) to swap x and y. The numbers kind of flow through each other and end up swapped.
void swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; return; }
Multi-Coloured Swap Shop ended on 1982-03-27.
void swap (int* a, int* b) { if (!a !b) return; // can't swap a pointer to null *a^=*b^=*a^=*b; }