fork download
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #define SWAP(a,b) do ((&(a))!=(&(b)))?((a)^=(b)^=(a)^=(b)):((a)=(a)); while (0)
  4. char *p1="1" ,*p2="2" ;
  5. char c1=1 , c2=2 ;
  6. short s1=1 , s2=2 ;
  7. int i1=1 , i2=2 ;
  8. int64_t I1=1ll, I2=2ll;
  9. float f1=1.0f, f2=2.0f;
  10. double d1=1.0 , d2=2.0 ;
  11. int main() {
  12. SWAP(*(int*)&p1,*(int*)&p2); printf("char * %5s, %5s\n",p1,p2);
  13. SWAP(c1,c2); printf("char %5d, %5d\n",c1,c2);
  14. SWAP(s1,s2); printf("short %5d, %5d\n",s1,s2);
  15. SWAP(i1,i2); printf("int %5d, %5d\n",i1,i2);
  16. SWAP(I1,I2); printf("__int64 %5lld,%5lld\n",I1,I2);
  17. SWAP(*(int *)&f1,*(int *)&f2);printf("float %5g, %5g\n",f1,f2);
  18. SWAP(*(int64_t *)&d1,*(int64_t *)&d2);printf("double %5lg, %5lg\n",d1,d2);
  19.  
  20. SWAP(c1,c1);
  21. printf("%d\n",c1);
  22. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
char *         2,       1
char           2,       1
short          2,       1
int            2,       1
__int64     2,    1
float          2,       2
double        2,      2
2