Scope of a variable outside main in C

前端 未结 7 593
深忆病人
深忆病人 2020-12-15 21:41

Consider the code:

#include 

int x;

int main (void) 
{ }

The value of x is 0 inside main

相关标签:
7条回答
  • 2020-12-15 22:35

    It's not static. It's global. You can declare it extern in a different compilation unit, but space will be allocated for it in this one. Globals are always initialized to 0 if they aren't given initializers, by the way.

    0 讨论(0)
提交回复
热议问题