设为首页 加入收藏

TOP

C语言的外部变量extern
2015-01-22 21:34:43 来源: 作者: 【 】 浏览:72
Tags:语言 外部 变量 extern
C语言的存储类型可分为:extern、auto、static、register。

外部变量定义在函数之外,通过同一个名字对外部变量的所有引用(即使这种引用来自于单独编译的不同函数),实际上都是引用同一个对外部变量的所有引用(C标准中把这一性质称为外部链接)。因此外部变量可以在全局范围内访问。


getChar.c:

#include
#include
extern char str[];//头文件中不用声明
int index_str = 0;
char getChar(){
return str[index_str++];
}


getStr.c:

#include
#include
char str[255];
/*get the testfile string */
void getStr(char* filename){
int index = 0;
FILE* fp;
if( (fp = fopen(filename,"r") ) == NULL){
printf("open test_file fail !!!\n");
exit(1);
}
while((str[index++] = getc(fp))!=EOF);
str[index] = '\0';/*结尾标志*/
fclose(fp);
}


http://blog.csdn.net/pipisorry/article/details/25346379

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Objective-c中的Block(块)详解 下一篇C语言基础知识之综合案例(1)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: