#include <stdio.h>
int x;

void mondai1(int b){
    x = b;
}

void mondai2(void){
    static int c = 10;
    x = c;
    c++;
}

int mondai3(int d){
    x++;   // グローバル x
    d++;   // ローカル d
    return d;
}

int main(void) {

    // 1回目：x はグローバル、初期値 0（GA）
    printf("x = %d [GA: グローバル変数は0で初期化される]\n", x);

    // 2回目：x = 101 を代入（GA）
    x = 101;
    printf("x = %d [GA: mainで101を代入した]\n", x);

    // 3回目：mondai1(102) により x = 102（GA）
    mondai1(102);
    printf("x = %d [GA: mondai1で102を代入した]\n", x);

    // 4回目：mondai2 を3回呼ぶ → static c が 10→11→12→13 と変化
    mondai2();  // x = 10
    mondai2();  // x = 11
    mondai2();  // x = 12
    printf("x = %d [GS: static変数cが3回インクリメントされて12になった]\n", x);

    // 5回目：for文内のローカル変数 x（LA）
    for (int i = 103; i < 104; i++){
        int x = i;  // ローカル x
        printf("x = %d [LA: for文内でi(103)を代入した]\n", x);

        // 6回目：mondai3 によりローカル x に戻り値 104 を代入（LA）
        x = mondai3(i);
        printf("x = %d [LA: mondai3の戻り値104を代入した]\n", x);
    }

    // 7回目：グローバル x は mondai3 により 12→13（GA）
    printf("x = %d [GA: mondai3でグローバルxが++され13になった]\n", x);

    return 0;
}

