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