In the following code, why is the variable i
not assigned the value 1
?
#include
int main(void)
{
int
In the case when val is not zero, the execution jumps directly to the label default. This means that the variable i
, while defined in the block, isn't initialized and its value is indeterminate.
6.8.2.4 The switch statement
- A switch statement causes control to jump to, into, or past the statement that is the switch body, depending on the value of a controlling expression, and on the presence of a default label and the values of any case labels on or in the switch body. A case or default label is accessible only within the closest enclosing switch statement.