CPP Switch Statement MCQ
Cpp MCQ- Home
- Tutorials
- Cpp
- Switch Statement
- Multiple Choice Question
(1) What will happen if we miss break statement after true case of switch statement ?
A) Compiler will generate error
B) Switch will not execute
C) Remaining case will not match
D) Default statement will not execute
Explanation
If we skip/miss to use break statement then all remaining case statements will not match and all remaining statements will also executed till occurrence of break statement. So that it is good practice to add break statement after each case statement.
(2) Which of the following is used after case keyword?
A) Variable
B) Constant
C) Expression
D) Operator
Explanation
Constant is used after case keyword and followed by Colon This constant is matched with the result of arithmetic expression specified in switch statement.
(3) How many case statements are allowed before single break statement in switch statement?
A) Only one
B) Maximum two
C) 4
D) Multiple
Explanation
We can write multiple case statements before single break statement depending upon algorithm.
(4) Which of the following operator is used after case keyword in switch statement?
A) : (colon)
B) ; (Semi colon)
C) , (comma)
D) . (dot)
Explanation
Colon operator is used after case statement.
(5) default statement is ____________ in switch statement.
A) Mandatory
B) Optional
C) Enforced
D) None of these
Explanation
default statement is optional to use in switch statement. But it is good practice to use default in every switch statement.
(6) Which of the following symbol is used after case keyword in switch statement ?
A) :
B) ;
C) .
D) ,
Explanation
Colon is used after case keyword.
(7) Which of the following expression used by switch statement ?
A) Arithmetic
B) Relational
C) Logical
D) All
Explanation
switch statement uses arithmetic expression / constant literal that return any constant literal. After this will match with coming case statements.
(8) switch statement is good alternative of
A) if
B) if else
C) if else if
D) nested if
Explanation
Switch statement may have multiple case statements in its body. if one case does not true then other case will check and so on up to N cases. If all cases does not true then the default statement will execute. So that it is good alternative of if else if statement.