fork download
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #define BUF_SIZE 256
  4.  
  5. int a; // .bss
  6. static int b; // .bss
  7. int c = 3; // .data
  8.  
  9. void foo(char **output)
  10. {
  11. static int d = 0, e = 5; // d — .bss, e — .data
  12. /* auto */ int f = 0; // stack
  13.  
  14. ++a, ++d, ++f;
  15.  
  16. const char *fmt = "%d %d %d %d %d %d"; // .rodata
  17. *output = malloc(BUF_SIZE); // heap
  18.  
  19. snprintf(*output, BUF_SIZE, fmt, a, b, c, d, e, f);
  20. }
  21.  
  22. int main(void)
  23. {
  24. static char *output; // The pointer is in .bss (defaults to NULL)!
  25. for (register int i = 0; i < 5; ++i) {
  26. foo(&output);
  27. puts(output);
  28. free(output);
  29. }
  30. exit(EXIT_SUCCESS);
  31. }
  32.  
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
1 0 3 1 5 1
2 0 3 2 5 1
3 0 3 3 5 1
4 0 3 4 5 1
5 0 3 5 5 1