Will a value live perpetually when there's no reference to it?

前端 未结 8 1271
鱼传尺愫
鱼传尺愫 2021-02-13 07:02

Suppose the following minimal code:

#include 
char character = \'c\';
int main (void)
{
    char character = \'b\';
    printf(\"The current value         


        
8条回答
  •  自闭症患者
    2021-02-13 07:36

    You have two separate variables named character: one at file scope set to 'c', whose lifetime is the lifetime of the program, and one in main set to 'b', whose lifetime is that of its scope.

    The definition of character in main masks the definition at file scope, so only the latter is accessible.

提交回复
热议问题