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

前端 未结 8 1221
鱼传尺愫
鱼传尺愫 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:48

    After the declaration of character in main, any reference to character in that function refers to that one, not the one at global scope. We call this shadowing.

    As for the effect on memory, you can't say due to the as-if rule adopted by the language: a compiler might optimise to

    #include 
    int main()
    {
         printf("The current value of head is b");
    }
    

    for example.

提交回复
热议问题