#include<stdio.h>
void main()
{
int a = 4;
switch (a)
{
case 4:
int res = 1;
printf("%d",res);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
当我用 gcc 编译这段代码时,我得到了错误
root@ubuntu:/home/ubuntu# gcc test.c -o t
test.c: In function ‘main’:
test.c:9:4: error: a label can only be part of a statement and a declaration is not a statement
int res = 1;
Run Code Online (Sandbox Code Playgroud)
但是当我添加时;,case 4:;我可以编译我的代码。
有什么问题,为什么要;解决这个问题?