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の値が指定されていないので、グローバル変数が初期化される]\n",x);
  18. x = 101;
  19. printf("x = %d [GS:18行で101を代入した]\n",x);
  20. mondai1(102);
  21. printf("x = %d [GS:20行目で関数mondai1を呼び出し、102を代入]\n",x);
  22. mondai2();
  23. mondai2();
  24. mondai2();
  25. printf("x = %d [GS:22行目柄関数mondai2を3回呼び出し、10→11→12になり、12を代入]\n",x);
  26. for(int i = 103;i<104;i++){
  27. int x = i;
  28. printf("x = %d [LA:27行で103を代入]\n",x);
  29. x = mondai3(i);
  30. printf("x = %d [LA:29行目で関数mondai3を呼び出し、++した]\n",x);
  31. }
  32. printf("x = %d [GS:29行目で関数mondai3が呼び出され、グローバル関数が++した]\n",x);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
x = 0 [GS:2行目のxの値が指定されていないので、グローバル変数が初期化される]
x = 101 [GS:18行で101を代入した]
x = 102 [GS:20行目で関数mondai1を呼び出し、102を代入]
x = 12 [GS:22行目柄関数mondai2を3回呼び出し、10→11→12になり、12を代入]
x = 103 [LA:27行で103を代入]
x = 104 [LA:29行目で関数mondai3を呼び出し、++した]
x = 13 [GS:29行目で関数mondai3が呼び出され、グローバル関数が++した]