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

后端 未结 5 2149
名媛妹妹
名媛妹妹 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:22

    The second version doesn't have an initializer for gvar. gvar is declared and defined at global scope without an initializer. It has static storage duration, so it is initialized with zero.

    The assignment in main is just that: an assignment, not an initialization.

提交回复
热议问题