I have written this C code in which I'm declaring a variable inside switch body with initialializing it to 10.But when I'm running this code it is printing some garbage value.
#include <stdio.h>
int main()
{
switch(2) {
int x=10;
case 1: printf("Case 1: %d\n",x);
break;
case 2: printf("Case 2: %d\n",x);
break;
}
system("pause");
return 0;
}
Is their anyone who can explain even if the variable x is declared why is it not initialized to 10 and some garbage value is printed.