哪個大神能給我講講這個程序,感覺有點混亂
#include <stdio.h>
void fn()
{
? ? static int x = 1; ? //定義靜態(tài)局部變量
? ? x*=2;
? ? printf("x=%d\n",x); ? ??
}
int main()
{
? ? int i;
? ? for(i=0;i<5;i++)
? ? {
? ? ? ? fn();
? ? }
? ? extern int x; ? ? ?//調(diào)用外部變量
? ? printf("x=%d\n",x);
? ? return 0;
}
int x=100;
2016-09-16
首先從main函數(shù)看起,定義了一個for循環(huán),其中調(diào)用了fn()函數(shù),然后來看fn(),定義了一個靜態(tài)的局部變量,是一個簡單的乘法,因此可知這個循環(huán)就是循環(huán)5次,每次乘以2然后輸出。循環(huán)結(jié)束后接著調(diào)用了外部變量x,這個x指的是main函數(shù)之后定義的int x=100,然后輸出。