fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int x;
  5.  
  6. struct A {
  7. int a;
  8. int b[];
  9. };
  10.  
  11. struct B {
  12. int a;
  13. int *b;
  14. };
  15.  
  16. int main(void) {
  17. printf("%zu\n", sizeof(x));
  18. printf("%zu\n", sizeof(struct A));
  19. printf("%zu\n", sizeof(struct B));
  20.  
  21. struct B b = {0};
  22. b.b = (int *)malloc(4 * sizeof(int));
  23. free(b.b);
  24. /*
  25.   struct A a = {0};
  26.   a.b = (int *)malloc(4 * sizeof(int)); // compile error
  27.   free(a.b); // don't free (may be cause to runtime error)
  28. */
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
4
4
16