fork download
  1. #include <stdio.h>
  2. int a,b=5,c;
  3. //global variable a=0,b=5 and c=0 (a and c initialized by bss)
  4.  
  5. int main(void) {
  6. int b,c;
  7. //local b initialized local c initialised (local c=0)
  8. a=20;
  9. //(global a updated) global a=20 global b=5 global c=0
  10. b=function1();
  11. //local b=output of function 1 local b=25
  12. function3();
  13. //printf("a= %d\nb= %d\nc= %d\n",a,b,c); (commented out)
  14. //This prints local values of c (from this block main function and global of a)
  15. return 0;
  16. }
  17.  
  18. int function1(){
  19. int a=50;
  20. int b=20;
  21. //global a=20 global b=5 global c=0
  22. //local a and b initialized local a=50 local b=20
  23. c=function2(b); //local b sent as parameter of function2 (b=20)
  24. //global c updated global c= output of function2 global c=25
  25. return c;
  26. }
  27. int function2(int b){
  28. //global a=20 global b=5 global c=0
  29. b=a+5;
  30. //local b= global a + 5
  31. return b;
  32. }
  33. int function3(){ ///prints all global values
  34. printf("a= %d\nb= %d\nc= %d\n",a,b,c);
  35. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
a= 20
b= 5
c= 25