error: extern declaration of 'i' follows declaration with no linkage

前端 未结 3 1599
心在旅途
心在旅途 2020-12-07 03:39

In the following program, I thought that extern int i; will change the following i to refer to the i defined outside main

3条回答
  •  遥遥无期
    2020-12-07 04:19

    #include 
    
    int i=1;  // external variable
    
    int main()
    {
        int i=2;            // local variable
        printf("%d\n", i);  // print local variable i==2
    
        {
        extern int i;       // point to external variable
        printf("%d\n", i);  // print external variable i==1
        }
    
        return 0;
    }
    

提交回复
热议问题