fork download
  1. #include <stdio.h>
  2.  
  3. // Global variables (all start at 0)
  4. int a, b, c, d;
  5.  
  6. // g1 prints: a (global), b (param), c (param), d (global)
  7. void g1(int b_param, int c_param) {
  8. printf("%d %d %d %d\n", a, b_param, c_param, d);
  9. }
  10.  
  11. // g2 just forwards its args into g1
  12. void g2(int a_param, int c_param) {
  13. g1(a_param, c_param);
  14. }
  15.  
  16. // g3 sets up its own locals, calls g1 twice and g2 once, then returns b_local
  17. int g3(int c_param, int a_param) {
  18. int b_local = 3;
  19.  
  20. // first call
  21. g1(a_param, b_local);
  22.  
  23. // inner block with its own c_local and d_local
  24. {
  25. int c_local = 8;
  26. int d_local = 4;
  27. (void)c_local; // avoid “unused variable” warning
  28. (void)d_local;
  29. g2(a_param, b_local);
  30. }
  31.  
  32. // third call
  33. g1(a_param, b_local);
  34.  
  35. return b_local;
  36. }
  37.  
  38. int main(void) {
  39. int a_local = 4;
  40. int b_local = 5;
  41.  
  42. // first g3: a_local becomes return of g3( b_local, c /*global*/ )
  43. a_local = g3(b_local, c);
  44.  
  45. // second g3: return value is ignored
  46. g3(b_local, a_local);
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0 0 3 0
0 0 3 0
0 0 3 0
0 3 3 0
0 3 3 0
0 3 3 0