fork download
  1. #include <stdio.h>
  2.  
  3. #define SWAP1(x,y) (x = x ^ y , y = x ^ y , x = x ^ y )
  4. #define SWAP2(x,y) (x^=y^=x^=y)
  5. #define SWAP3(x,y) (x^=y^=x^=y^=x^=y^=x^=y^=x^=y)
  6.  
  7.  
  8. int main(void) {
  9.  
  10. int a = 5, b=-30;
  11. printf("Original a=%d, b=%d\n",a,b);
  12. SWAP1(a,b);
  13. printf("SWAP1 -> a=%d, b=%d\n",a,b);
  14. SWAP2(a,b);
  15. printf("SWAP2 -> a=%d, b=%d\n",a,b);
  16. SWAP3(a,b);
  17. printf("SWAP3 -> a=%d, b=%d\n",a,b);
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 5260KB
stdin
Standard input is empty
stdout
Original a=5, b=-30
SWAP1 -> a=-30, b=5
SWAP2 -> a=5, b=-30
SWAP3 -> a=-30, b=5