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 [グローバル変数の初期値]\n", x);
  23. x = 101;
  24. printf("x = %d [xに101を代入]\n", x);
  25. mondai1(102);
  26. printf("x = %d [mondai1でxに102を代入]\n", x);
  27. mondai2();
  28. mondai2();
  29. mondai2();
  30. printf("x = %d [mondai2を3回繰り返し、xは最終的に12]\n", x);
  31. for (int i = 103; i<104; i++){
  32. int x = i; // ループ内だけのローカル変数
  33. printf("x = %d [ループ内のローカル変数xにi(103)を代入]\n", x);
  34. x = mondai3(i);
  35. printf("x = %d [mondai3の戻り値(104)をローカル変数xに代入]\n", x);
  36. }
  37. printf("x = %d [グローバル変数xの値 (mondai3内で13に更新済)]\n", x);
  38. return 0;
  39. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
x = 0 [グローバル変数の初期値]
x = 101 [xに101を代入]
x = 102 [mondai1でxに102を代入]
x = 12 [mondai2を3回繰り返し、xは最終的に12]
x = 103 [ループ内のローカル変数xにi(103)を代入]
x = 104 [mondai3の戻り値(104)をローカル変数xに代入]
x = 13 [グローバル変数xの値 (mondai3内で13に更新済)]