是否有可能主后声明的变量具有文件范围是什么? [英] Is it possible that a variable declared after the main has file scope?
本文介绍了是否有可能主后声明的变量具有文件范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行此code之后:
#include <stdio.h>
int x;
int main(void)
{
printf("%d\n",x);
return 0;
}
int x=5;
我所期望的输出应为 0
。由于在顺序控制结构程序的 INT X;
应先执行 0
打印,最后 INT X = 5;
应该执行。但它给输出 5
。
I expected the output should be 0
. Because of the sequence control structure of the program int x;
should be executed first and then 0
is printed and finally int x=5;
should be executed. But it is giving the output 5
.
该计划是如何访问 5
为 X
在的printf
?
How is the program accesses 5
for the x
in printf
?
推荐答案
第一个充当向前声明,后者作为实际的定义。
The first acts as a forward declaration, and the later acts as the actual definition.
这篇关于是否有可能主后声明的变量具有文件范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文