Why's initializing a global variable with return value of a function failing at declaration,but works fine at file scope?

后端 未结 5 2148
名媛妹妹
名媛妹妹 2020-12-19 04:51

An 80k reputation contributor R.. told me on SO that we can\'t initialize global variables with the return value of a function as that\'s not c

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 05:16

    You can maybe think of it like this: when main() starts, all global variables must already have their initializer values. And they can't, as you've been told, get those by calling functions since main() is really where execution starts, in a C program.

提交回复
热议问题