static用法

#include "stdafx.h"

static int a;

int display(int m)
{
 static int b=2;//静态局部变量在编译时赋初值,即只赋值一次。运行设置断点可以检验
 //int b=0;//函数调用时赋值,必须初始化
 b = b + m;
 return b;
}

int _tmain(int argc, _TCHAR* argv[])
{
   int c;
   a = 3;
   printf("%d\n",a);
   c = display(a);
   printf("%d\n",c);
   c = display(a);
   printf("%d\n",c);
   getchar();
   
   return 0;
}

posted @ 2013-09-11 15:07  露水上的青蛙  阅读(148)  评论(0编辑  收藏  举报