Variable definition inside switch statement
问题 In the following code, why is the variable i not assigned the value 1 ? #include <stdio.h> int main(void) { int val = 0; switch (val) { int i = 1; //i is defined here case 0: printf("value: %d\n", i); break; default: printf("value: %d\n", i); break; } return 0; } When I compile, I get a warning about i not being initialized despite int i = 1; that clearly initializes it $ gcc -Wall test.c warning: ‘i’ is used uninitialized in this function [-Wuninitialized] printf("value %d\n", i); ^ If val =