首页 > 代码库 > error: a label can only be part of a statement and a declaration is not a statement

error: a label can only be part of a statement and a declaration is not a statement

GCC:

error: a label can only be part of a statement and a declaration is not a statement

 

switch(a){        swtch(a){

case 1:         case 1:

....................       {

....................        ...............

....................        ...............

break;          ................

case 2:         }

break;          break;

}            case 2:

             break;

            }

Error         OK

 

 

case1://此块代码不能再声明变量,如果你声明变量就会报错,除非用括号括起来,这是编译器的问题,也可以说是C语言的规定。写代码的时候注意就成了。就像C语言再声明的时候不能赋值一样,记住就好了。break;希望对你有所帮助。

error: a label can only be part of a statement and a declaration is not a statement