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