[Solved] Initialize variables inside a switch statement [duplicate]


In C++ this code is ill-formed because you cannot jump into the scope of a variable.

In C the code is undefined behaviour: int i; inside the switch block exists, however by jumping to case 1: you bypassed the part where the value 2 would have been assigned to i. So in fact you are attempting to print an uninitialized variable.

2

solved Initialize variables inside a switch statement [duplicate]