Sunday, December 31, 2023

C Branching Statements MCQs with Answer - Set 2

C - Branching Statements MCQs Set 2


Followings are 10 important C programming MCQs on branching statements, along with their answers:

1. Which of the following is not a branching statement in C?
a) if 
b) switch 
c) while 
d) 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 5 
b) x is less than or equal to 5 
c) Compile error 
d) Runtime error

Answer: a) x is greater than 5

3. Which of the following is a multiway decision statement in C?
a) if 
b) switch 
c) for 
d) while

Answer: b) switch

4. Is the default case compulsory in the switch case statement?
a) Yes 
b) No 
c) Depends on the compiler
d) None of the above

Answer: b) No

5. What happens when a break statement is encountered in a switch case?
a) The program terminates
b) The switch statement terminates 
c) The current loop terminates
d) 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 statement 
b) The block inside the else statement 
c) Both blocks 
d) 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) Yes 
b) No 
c) Depends on the compiler 
d) 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) 4 
b) 3 
c) 6 
d) Compile error

Answer: c) 6

9. Can a break statement be used inside an if statement?
a) Yes 
b) No 
c) Depends on the compiler 
d) 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 cases 
b) To terminate the switch statement
c) To cause a compile error 
d) None of the above

Answer: a) To handle all cases that are not explicitly handled by other cases

< HOME

No comments:

Post a Comment