【发布时间】:2021-01-15 02:53:28
【问题描述】:
#include<stdio.h>
void main()
{
int a = 4;
switch (a)
{
case 4:
int res = 1;
printf("%d",res);
break;
}
}
当我用 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;
但是当我像case 4:; 这样添加; 时,我可以编译我的代码。
是什么问题以及为什么; 解决这个问题?
【问题讨论】:
标签: c switch-statement label declaration