目录下新建 extern.h 文件,代码如下。
extern.h
extern int i = 233;
执行下面的代码,即可访问外部变量。
#include <stdio.h> #include "extern.h" int main(int argc, char const *argv[]) { printf("%d\n", i); return 0; }