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

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

    #include 
    char character = 'c';
    int main (void)
    {
        char character = 'b';
        printf("The current value of head is %c\n", character);
        printc();
    }
    
    void printc()
    {
        printf("%c", character);
    }
    

    It makes it all clear. It is not destroyed it is just shadowed.

    Output: The current value of head is b
    c

提交回复
热议问题