Contact: aviboots(AT)netvision.net.il
38,119 questions
49,726 answers
573 users
#include <stdio.h> #define SWAP(x, y) ((&(x) == &(y)) ? (x) : ((x)^=(y), (y)^=(x), (x)^=(y))) int main() { long x = 3; long y = 7; SWAP(x, y); printf("x = %ld, y = %ld\n", x, y); return 0; } /* run: x = 7, y = 3 */
#include <stdio.h> #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) int main(void) { int x = 8290, y = 1000; SWAP(x, y); printf("x = %d y = %d\n", x, y); return 0; } /* run: x = 1000 y = 8290 */