Which data type is NOT allowed in a C++ switch statement?
A
int B
char C
float D
enum
Analysis & Theory
C++ switch statements only work with integral types like int, char, enum, but not with float or double.
What happens if a `break` is omitted in a switch case?
A
Compiler error B
Only the current case runs C
Fall-through to the next case D
Switch terminates
Analysis & Theory
Without a `break`, execution 'falls through' to the next case.
Which of the following keywords is used to exit a switch case?
A
exit B
return C
stop D
break
Analysis & Theory
The `break` statement is used to exit a switch case block.
How many `default` cases can a switch statement have?
A
0 B
1 C
2 D
Unlimited
Analysis & Theory
A switch can have at most one `default` case.
What will be the output?
```cpp
int x = 2;
switch(x) {
case 1: cout << "One";
case 2: cout << "Two";
case 3: cout << "Three";
}
```
A
Two B
TwoThree C
Three D
No output
Analysis & Theory
Without `break`, the execution will fall through from case 2 to case 3. Output: TwoThree
Which of the following is true about the default case in switch?
A
It must be at the end B
It is optional C
It must be first D
It causes a compile error
Analysis & Theory
The `default` case is optional and can be placed anywhere in the switch block.
What is required in each `case` label in a switch statement?
A
A string B
A constant expression C
A variable D
A function
Analysis & Theory
Case labels must be constant expressions known at compile time.
Which of the following can be used in a switch expression?
A
float B
string C
bool D
int
Analysis & Theory
The switch expression must evaluate to an integer, char, or enum type.
What is the purpose of the `break` statement in a switch?
A
To start a new case B
To jump to the next case C
To exit the switch block D
To stop compilation
Analysis & Theory
The `break` statement exits the switch block after executing a case.
Can `switch` statements be nested in C++?
A
No B
Yes, but only two levels C
Yes, any level D
Only with integers
Analysis & Theory
C++ allows switch statements to be nested to any level, though it's rarely recommended.