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[GS:グローバル変数なので初期値は0]\n" , x);
  20. x=101;
  21. printf("x=%d[GS:グローバル変数xに101を代入した]\n" , x);
  22. mondai1(102);
  23. printf("x=%d[GS:mondai1関数でxに102を代入した]\n" , x);
  24. mondai2();
  25. mondai2();
  26. mondai2();
  27. printf("x=%d[GS:mondai2関数を3回呼び出し、static変数cの値を順に代入した]\n" , x);
  28. for (int i=103;i<104;i++){
  29. int x=i;
  30. printf("x=%d[LA:for文内のローカル変数xにiの値103を代入した]\n", x);
  31. x=mondai3(i);
  32. printf("x=%d[LA:mondai3関数の戻り値104をローカル変数xに代入した]\n" , x);
  33. }
  34. printf("x=%d[GS:mondai3関数でグローバル変数xを1増やした]\n" , x);
  35. return 0;
  36.  
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
x=0[GS:グローバル変数なので初期値は0]
x=101[GS:グローバル変数xに101を代入した]
x=102[GS:mondai1関数でxに102を代入した]
x=12[GS:mondai2関数を3回呼び出し、static変数cの値を順に代入した]
x=103[LA:for文内のローカル変数xにiの値103を代入した]
x=104[LA:mondai3関数の戻り値104をローカル変数xに代入した]
x=13[GS:mondai3関数でグローバル変数xを1増やした]