posted 16 years ago
Gaurav, your statement The default case is always executed if no other case before it has been irrespective of whether cases after it will be executed or not. According to this statement the following program should produce output as 6 but it is 4 only. Can you explain why in this case it is 4 only.
According to your statement, the flow is as follows.
case 2: i != 2 so skip;
case 4: i != 4 so skip;
default: if no other case has been accepted till now, accept this one. so j = j + 2; j = 2;
case 0: i == 0; j = j + 4; j = j + 2; j = 6;