In C,why is multiple declarations working fine for a global variable but not for a local variable?

后端 未结 3 1073
面向向阳花
面向向阳花 2020-11-30 09:12

In the following code, why do multiple declarations (and one definition) work fine for a global variable x but not for a local variable y which is

3条回答
  •  迷失自我
    2020-11-30 10:01

    In C and C++, int y; within a function is both a declaration and a definition.

    In C, int x; in the file scope (outside any function) is a declaration and a tentative defintion. Multiple tentative definitions are allowed; only one definition is allowed.

提交回复
热议问题