fork download
  1. #include <stdio.h>
  2.  
  3. // globals (initialized to 0)
  4. int a, b, c, d;
  5.  
  6. void g1(int b, int c) {
  7. // free a,d refer to globals
  8. printf("%d %d %d %d\n", a, b, c, d);
  9. }
  10.  
  11. void g2(int a_, int c_) {
  12. // parameters renamed so we don’t shadow globals
  13. g1(a_, c_);
  14. }
  15.  
  16. int g3(int c_, int a_) {
  17. int b_ = 3;
  18. g1(a_, b_);
  19.  
  20. { // inner block with its own c,d
  21. int c = 8;
  22. int d = 4;
  23. g2(a_, b_);
  24. }
  25.  
  26. g1(a_, b_);
  27. return b_;
  28. }
  29.  
  30. int main(void) {
  31. int a = 4, b = 5; // locals shadow globals inside main
  32. // first call: a=4 (local), b=5 (local), global c==0
  33. a = g3(b, c);
  34. // second call: b (local)==5, a (local)==3
  35. g3(b, a);
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5300KB
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