C Switch Case MCQ Questions and Answers
Q. What is the switch-case statement in C used for?
A. To perform repetitive tasks based on a conditionB. To make decisions based on the value of an expression
C. To loop through a block of code a specified number of times
D. To handle errors and exceptions
Q. What is the default behavior if no break statement is used in a switch case?
A. The program will terminateB. The next case will be executed
C. The program will enter an infinite loop
D. The default case will be executed
Q. What is the data type of the expression in a switch case?
A. The expression must be of an integer data typeB. The expression can be of any data type
C. The expression must be a character
D. The expression must be a floating-point number
Q. What is the purpose of the "default" case in a switch statement?
A. To handle invalid inputB. To provide a default value if no case matches
C. To exit the switch statement
D. To provide a default case if no break statement is used
Q. Can a switch case have multiple conditions for a single case?
A. Yes, multiple conditions can be specified using logical operatorsB. No, each case can have only one condition
C. Yes, multiple conditions can be specified using the comma operator
D. Yes, multiple conditions can be specified using the OR operator
Q. Can a switch case have floating-point numbers as case labels?
A. Yes, floating-point numbers are allowedB. No, only integer values are allowed
C. Yes, but they must be converted to integers
D. Yes, but they must be enclosed in quotes
Q. Can a switch case have variables as case labels?
A. Yes, variables are allowed as case labelsB. No, only constant values are allowed
C. Yes, but the variables must be declared before the switch statement
D. Yes, but the variables must be of the same data type as the expression
Q. Can a switch case have duplicate case labels?
A. Yes, duplicate case labels are allowedB. No, each case label must be unique
C. Yes, but only if they have different code blocks
D. Yes, but they must be of the same data type
Q. What is the purpose of the "break" statement in a switch case?
A. To exit the entire programB. To exit the current case and continue to the next one
C. To exit the switch statement and skip the remaining cases
D. To exit a loop within the switch case
Q. Can a switch case have a range of values for a case label?
A. Yes, a range can be specified using the hyphen (-) operatorB. No, each case label must be a single value
C. Yes, a range can be specified using the colon (:) operator
D. Yes, a range can be specified using the comma (,) operator