c 全局静态变量的实例解释其作用域

来源:互联网 发布:ov7620数据手册 编辑:程序博客网 时间:2024/05/21 14:53

glovar.h 文件

#pragma oncestatic int glo;

one.h 文件

void getone();
one.cpp 文件
#include "stdafx.h"#include "glovar.h"#include "one.h"void getone(){glo = 13;printf("one: glo is %d \n",glo);}

two.h 文件

void gettwo();

two.cpp 文件

#include "stdafx.h"#include "glovar.h"#include "one.h"#include "two.h"void gettwo(){glo = 15;getone();printf("two: glo is %d \n",glo);}
main.cpp 文件

#include "stdafx.h"#include "one.h"#include "two.h"int _tmain(int argc, _TCHAR* argv[]){gettwo();return 0;}
运行结果:

one: glo is 13
two:  glo is 15





0 0
原创粉丝点击