Variable declaration after goto Label

前端 未结 7 2270
我在风中等你
我在风中等你 2020-12-04 15:20

Today I found one interesting thing. I didn\'t know that one can\'t declare a variable after a goto label.

Compiling the following code

#include <         


        
7条回答
  •  孤街浪徒
    2020-12-04 15:34

    If you know why you can't create variables inside case statement of switch, basically its the same reason why you cant do this too. As a fix, you can try this,

    #include 
    int main() {
        int x = 5;
        goto JUMP;
        printf("x is : %d\n",x);
    JUMP:
        {                                              //Note this
           int a = 0;  // <=== no more error..
           printf("%d",a);
        }                                             //Note this
    }
    

提交回复
热议问题