#include<stdio.h>

int count=3;

int main()

    int i,sum,count=2;

    for(i=0,sum=0;i<count;i+=2,count++)

    { 

        static int count=4;

        count++;

        if(i%2==0)

        { 

            extern int count;

            count++;

            sum+=count;

        }

        sum+=count;

    }

    printf("sum=%d\ncount=%d\n",sum,count);

    return 0;

}


    i<count 中 count=2; 进入for循环,static int count=4 中 count 是静态局部变量,使用后保存当前的值,count++ 后,此时 count 变为 5,进入if语句,extern int count,此时 count 为外部的全局变量,count++;此时 count 变为4,执行 sum+=count;sum=4。出if语句,执行 sum+=count, 此时 sum=4+5=9。进入for循环的调整部分,i+=2,count++,此时i=2,count=3;执行for循环的判断部分,2<3成立,进入for循环,继续往下执行,count++,此时count=6,进入if语句,count++,此时count为上次的值加1,所以count为5,sum+=count,则sum=9+5=14;再出if语句,sum+=count,则sum=14+6=20;再进入for循环的调整部分,i+=2,count++,此时i=4,count=4;条件部分4<4判断失败,出for循环,输出sum=20,count=4。程序结束。