Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: C 中的外部变量是什么?
C编程语言中的外部存储类和全局变量有什么区别?对我来说,它们似乎都是同一件事。请澄清。
extern变量是在另一个单元中定义的变量的声明。
extern
您在文件中声明它:.h
.h
extern int global_var;
如果你想在.c文件中使用它,你可以在全局范围内定义它。你应该使用它的源文件中的文件。include.h
.c
include
全局变量是在块外声明的变量。它们可以在程序中的任何地方访问。
请注意,了解声明变量和定义变量之间的区别非常重要: