C - Branching Statements MCQs Set 2
1. Which of the following is not a branching statement in C?
a) ifb) switchc) whiled) goto
Answer: c) while (while is a looping statement, not a branching statement)
2. What is the output of the following code?
int x = 10;if (x > 5) {printf("x is greater than 5");} else {printf("x is less than or equal to 5");}
a) x is greater than 5b) x is less than or equal to 5c) Compile errord) Runtime error
Answer: a) x is greater than 5
3. Which of the following is a multiway decision statement in C?
a) ifb) switchc) ford) while
Answer: b) switch
4. Is the default case compulsory in the switch case statement?
a) Yesb) Noc) Depends on the compilerd) None of the above
Answer: b) No
5. What happens when a break statement is encountered in a switch case?
a) The program terminatesb) The switch statement terminatesc) The current loop terminatesd) None of the above
Answer: b) The switch statement terminates
6. If the Boolean expression of an if statement evaluates to true, then which block of code is executed?
a) The block inside the if statementb) The block inside the else statementc) Both blocksd) None of the blocks
Answer: a) The block inside the if statement
7. Can a switch statement have multiple case labels with the same value?
a) Yesb) Noc) Depends on the compilerd) None of the above
Answer: a) Yes
8. What is the output of the following code?
int num = 4;switch (num + 2) {case 4: printf("4"); break;case 3: printf("3"); break;case 6: printf("6"); break;}
a) 4b) 3c) 6d) Compile error
Answer: c) 6
9. Can a break statement be used inside an if statement?
a) Yesb) Noc) Depends on the compilerd) None of the above
Answer: b) No
10. What is the purpose of the default case in a switch statement?
a) To handle all cases that are not explicitly handled by other casesb) To terminate the switch statementc) To cause a compile errord) None of the above