关于static的局部变量,全局寿命的例子

2176阅读 0评论2008-12-15 I-linux
分类:LINUX

static的"局部变量,全局寿命"的用法通过下面的例子来体现:
int test(void)
{
   int a=0;
   a++;
    printf("a=%d\n",a);
    
   return 0;
 
}
 
int test1(void)
{
   static int b=0;
   b++;
   printf("b=%d\n",b);
  
   return 0;
}
 
int main(void)
{
   test();
   test();
   test();
   test1();
   test1();
   test1();
   return 0;
}
 
程序运行结果:
a=1
a=1
a=1
 
b=1
b=2
b=3
上一篇:seizeof()和strlen()的区别
下一篇:Linux程式设计-时间处理