fork download
  1. #include <stdio.h>
  2.  
  3. struct bar
  4. {
  5. int data[9];
  6. };
  7.  
  8.  
  9. #if 0
  10. http://stackoverflow.com/questions/42916249/typecasting-to-constant-literal-why-this-output-of-a-c-program
  11.  
  12. ((struct bar*)1)
  13.  
  14. This is same as treating that value as a pointer to struct bar *.
  15. For example:
  16. int *p = 1
  17. ((struct bar*)p)
  18.  
  19. This is same as above.
  20.  
  21. #endif
  22.  
  23. int main(void) {
  24. printf("%d \n", ((struct bar*)1) + 1);
  25. printf("%d \n", ((struct bar*)-1) + 1);
  26. //printf("%d", ((struct bar*)1) + 1);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
37 
35