Is it possible that a variable declared after the main has file scope?

后端 未结 3 675
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 04:20

After running this code:

#include 
int x;
int main(void)
{
    printf(\"%d\\n\",x);
    return 0;
}
int x=5; 

I expected t

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 04:43

    Variable default values declared outside of functions get set before main ever runs. So what you are seeing is the correct behavior. Same goes for variables declared in other source files.

提交回复
热议问题