如何共享C文件之间的全局变量? [英] How do I share a global variable between c files?
本文介绍了如何共享C文件之间的全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我定义一个 .C
文件中的全局变量,我怎么能使用相同的变量的值在另一个 .C
文件?
If i define a global variable in a .c
file, how can i use the value of the same variable in another .c
file?
在file1.c
#include<stdio.h>
int i=10;
int main()
{
printf("%d",i);
return 0;
}
file2.c中
file2.c
#include<stdio.h>
int main()
{
//some data regarding i
printf("%d",i);
return 0;
}
如何能在第二个文件中使用的值 I
从第一个文件在这里。
推荐答案
文件1:
int x = 50;
文件2:
extern int x;
printf("%d", x);
这篇关于如何共享C文件之间的全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文