標(biāo)題: 作用域及初始化問題 [打印本頁]

作者: xiaojuan    時(shí)間: 2014-9-17 14:30
標(biāo)題: 作用域及初始化問題
                        #include<stdio.h>
void trystat(void);
int main (void)
{
int count;
for (count=1; count<=3; count++)
{
  printf ("Here comes iteration%d :\n",count);
  trystat( );
}
}
void trystat(void)
{
int fade = 1;
static int stay =1;  //靜態(tài)變量,只進(jìn)行一次初始化,所以從1開始
printf ("fade = %d  and stay= %d \n",fade++,stay++);
}
Here comes iteration 1 :
fade = 1  and stay = 1
Here comes iteration 2 :
fade = 1  and stay = 2
Here comes iteration 3 :
fade = 1  and stay = 3







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1