fork download
  1. #include <stdio.h>
  2. int x;
  3. void mondai1(int b) {
  4. x = b;
  5. }
  6. void mondai2(void) {
  7. static int c = 10;
  8. x = c;
  9. c++;
  10. }
  11. int mondai3(int d) {
  12. x++;
  13. d++;
  14. return d;
  15. }
  16. int main(void) {
  17. printf("x = %d [GS: 2行目でグローバル変数xの初期値は0]\n", x);
  18. x = 101;
  19. printf("x = %d [GS: 18行目でグローバル変数xに101を代入]\n", x);
  20. mondai1(102);
  21. printf("x = %d [GS: 20行目でmondai1を呼び、4行目でxに102を代入]\n", x);
  22. mondai2();
  23. mondai2();
  24. mondai2();
  25. printf("x = %d [GS: 22~24行目でmondai2を3回呼び、7~9行目で静的変数cが10、11、12と変化したため]\n", x);
  26. for (int i = 103; i < 104; i++) {
  27. int x = i;
  28. printf("x = %d [LA: 27行目でfor文内の自動変数xにi=103を代入]\n", x);
  29. x = mondai3(i);
  30. printf("x = %d [LA: 29行目でmondai3がdを103から104に増やし、その値をローカル変数xに代入]\n", x);
  31. }
  32. printf("x = %d [GS: 12行目でmondai3内でグローバル変数xを12から13に増加]\n", x);
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
x = 0 [GS: 2行目でグローバル変数xの初期値は0]
x = 101 [GS: 18行目でグローバル変数xに101を代入]
x = 102 [GS: 20行目でmondai1を呼び、4行目でxに102を代入]
x = 12 [GS: 22~24行目でmondai2を3回呼び、7~9行目で静的変数cが10、11、12と変化したため]
x = 103 [LA: 27行目でfor文内の自動変数xにi=103を代入]
x = 104 [LA: 29行目でmondai3がdを103から104に増やし、その値をローカル変数xに代入]
x = 13 [GS: 12行目でmondai3内でグローバル変数xを12から13に増加]