#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 in count=2; Enter for loop, static int count=4 count is a static local variable, after the current value is saved after use, count++, when Count becomes 5, enter the IF statement, extern int count, at which point the count is the outer global variable, cou nt++; When Count becomes 4, the sum+=count;sum=4 is executed. Out if statement, execute Sum+=count, at this time sum=4+5=9. Enter the adjustment portion of the For Loop, i+=2,count++, at which point the i=2,count=3 is executed, the judgment part of the For loop executes, 2<3 is established, enters for loop, continues execution, count++, count=6 at this time, enters if statement, count++, At this point count is added 1 for the last value, so count is 5,sum+=count, then sum=9+5=14, then the IF statement, Sum+=count, then sum=14+6=20, and then into the adjustment portion of the For Loop, i+=2,count++, at which time i= 4,count=4; conditional part 4<4 judgment fails, out for loop, output sum=20,count=4. The program ends.
Local variables, the application of global variables