#include<stdio.h>
void main()
{
int a = 4;
switch (a)
{
case 4:
int res = 1;
printf("%d",res);
break;
}
}
When I compiled this code with gcc I got error
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;
But when I add ;
like case 4:;
I can compile my code.
What is the problem and why ;
fix that?