IGDTUW 2026 Computer PYQ — What is the output of the following C++ program? #include <iostre… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
IGDTUW 2026 — Computer PYQ
IGDTUW | Computer | 2026
What is the output of the following C++ program?
#include <iostream>
using namespace std;
int main() {
int x = 3;
switch (x) {
case 1:
case 2:
cout << "A";
break;
case 3:
cout << "B";
default:
cout << "C";
}
return 0;
}
Choose the correct answer:
A.
A
B.
B
C.
BC
(Correct Answer)
D.
C
Correct Answer:
BC
Explanation
Detailed Solution
This problem evaluates how the switch statement handles execution flow and the absence of a break statement, a behavior known as fall-through.
Step-by-Step Code Walkthrough:
Initialization: The integer variable x is initialized with a value of 3:
x=3
Switch Evaluation: The control passes to the switch(x) block, matching the value of x. It jumps directly to case 3:.
Executing Case 3: Inside case 3:, the statement cout << "B"; executes, printing B to the output console.
The Fall-Through Effect: Crucially, there is no break; statement at the end of case 3:. Without a break, execution does not exit the switch block; instead, it automatically "falls through" into the next block, which is the default: case.
Executing Default: Because of the fall-through, the statement under default:, cout << "C";, executes as well, printing C right next to B.
Termination: The switch block concludes, and the program terminates cleanly with return 0;.
Combining the outputs from both blocks gives the final result: BC.
Explanation
Detailed Solution
This problem evaluates how the switch statement handles execution flow and the absence of a break statement, a behavior known as fall-through.
Step-by-Step Code Walkthrough:
Initialization: The integer variable x is initialized with a value of 3:
x=3
Switch Evaluation: The control passes to the switch(x) block, matching the value of x. It jumps directly to case 3:.
Executing Case 3: Inside case 3:, the statement cout << "B"; executes, printing B to the output console.
The Fall-Through Effect: Crucially, there is no break; statement at the end of case 3:. Without a break, execution does not exit the switch block; instead, it automatically "falls through" into the next block, which is the default: case.
Executing Default: Because of the fall-through, the statement under default:, cout << "C";, executes as well, printing C right next to B.
Termination: The switch block concludes, and the program terminates cleanly with return 0;.
Combining the outputs from both blocks gives the final result: BC.