What is the output of the following code? int switch(i)
20242024
What is the output of the following code?
int i = 5;
switch(i)
{
case 1: printf("One");
case 5: printf("Five");
case 10: printf("Ten");
default: printf("Other");
}
- A.
Five
- B.
Ten
- C.
FiveTen Other
- D.
Other
Attempted by 507 students.
Show answer & explanation
Correct answer: C
In the switch statement, when the case for i=5 is matched, the program will continue to execute all subsequentcases and the default case, as there are no 'break' statements.