Hi
Why does C allows declaration of variable inside switch block.
ex: foll prg does not gives "undeclared "b" error msg. but also does
not initialize b to 20
int a=1;
switch(a)
{
int b=20;
case 1: printf("b is %d\n",b);
break;
default:printf( "b is %d\n",b);
break;
}
this prints some garbage.
( yeah even though i got warning msg "unreachabl e code int b = 20" why
is it declaring inside switch block but not initializing b)
Why does C allows declaration of variable inside switch block.
ex: foll prg does not gives "undeclared "b" error msg. but also does
not initialize b to 20
int a=1;
switch(a)
{
int b=20;
case 1: printf("b is %d\n",b);
break;
default:printf( "b is %d\n",b);
break;
}
this prints some garbage.
( yeah even though i got warning msg "unreachabl e code int b = 20" why
is it declaring inside switch block but not initializing b)
Comment