fork download
  1. #include <stdio.h>
  2.  
  3. int x;
  4.  
  5. void mondai1(int b) {
  6. x = b;
  7. }
  8.  
  9. void mondai2(void) {
  10. static int c = 10;
  11. x = c;
  12. c++;
  13. }
  14.  
  15. int mondai3(int d) {
  16. x++;
  17. d++;
  18. return d;
  19. }
  20.  
  21. int main(void) {
  22. printf("x = %d[GS:3行目でグローバル変数は自動的に0で初期化される]\n", x);
  23.  
  24. x = 101;
  25. printf("x = %d[GS:24行目の101を代入]\n", x);
  26.  
  27. mondai1(102);
  28. printf("x = %d[GS:27行目でmondai1のグローバル変数xに102を代入]\n", x);
  29.  
  30. mondai2();
  31. mondai2();
  32. mondai2();
  33. printf("x = %d[GS:31行目でmondai2のstaticの変数cから順番にmondai2を3回代入]\n", x);
  34.  
  35. for (int i = 103; i < 104; i++) {
  36. int x = i;
  37. printf("x = %d[LA:36行目でfor文のiをxに代入]\n", x);
  38.  
  39. x = mondai3(i);
  40. printf("x = %d[LA:37行目のiを代入し、mondai3で++されたのがreturnで戻ってくる]\n", x);
  41. }
  42.  
  43. printf("x = %d[GS:17行目でmondai3内でグローバル変数xを12から13に増加]\n", x);
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5316KB
stdin
 
stdout
x = 0[GS:3行目でグローバル変数は自動的に0で初期化される]
x = 101[GS:24行目の101を代入]
x = 102[GS:27行目でmondai1のグローバル変数xに102を代入]
x = 12[GS:31行目でmondai2のstaticの変数cから順番にmondai2を3回代入]
x = 103[LA:36行目でfor文のiをxに代入]
x = 104[LA:37行目のiを代入し、mondai3で++されたのがreturnで戻ってくる]
x = 13[GS:17行目でmondai3内でグローバル変数xを12から13に増加]