PRACTICE • LEARN • GROW
Module 2 Final Quiz: Control Flow MCQs
Solve topic-wise placement questions and improve your skills.
Module 2 Final Quiz: Control Flow Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the output of the following C++ code snippet?
int age = 17;
if (age >= 18)
cout << "Adult";
else
cout << "Minor";
A.
Adult
B.
Minor
C.
17
D.
Compilation Error
Explanation & Key
Correct Answer:
2
What occurs in a C++ switch statement if a case block omits the 'break;' statement?
A.
The program crashes immediately
B.
The compiler rejects the code with a syntax error
C.
Execution 'falls through' and continues running the code in subsequent cases until a break or end of switch is reached
D.
The switch statement restarts from the first case
Explanation & Key
Correct Answer:
3
What is the output of this code snippet?
int val = 2;
switch (val) {
case 1: cout << "A";
case 2: cout << "B";
case 3: cout << "C";
default: cout << "D";
}
A.
B
B.
BCD
C.
ABCD
D.
D
Explanation & Key
Correct Answer:
4
How many times does the loop body execute in the following C++ code?
int i = 5;
do {
i++;
} while (i < 5);
A.
0 times
B.
1 time
C.
5 times
D.
Infinite loop
Explanation & Key
Correct Answer:
5
What are the three components bundled inside the parenthesis of a standard C++ for loop header: for (A; B; C)?
A.
Condition, Initialization, Break
B.
Initialization, Condition test, Increment/Update step
C.
Declaration, Memory allocation, Deletion
D.
Input, Process, Output
Explanation & Key
Correct Answer:
6
What is the output of this loop?
for (int i = 0; i < 5; i++) {
if (i == 2) continue;
cout << i;
}
A.
01234
B.
0134
C.
01
D.
234
Explanation & Key
Correct Answer:
7
What does the 'break' statement do when executed inside a nested loop?
A.
Terminates all outer loops and returns from main
B.
Exits only the nearest enclosing loop
C.
Skips to the next iteration of the outer loop
D.
Pauses execution for 1 second
Explanation & Key
Correct Answer:
8
Why is the 'goto' statement strongly discouraged in modern software engineering?
A.
It consumes too much CPU memory
B.
It bypasses structured control flow and produces tangled, hard-to-maintain 'spaghetti code'
C.
It cannot be compiled by modern GCC or Clang compilers
D.
It only works on floating point numbers
Explanation & Key
Correct Answer:
9
What is the output of the following loop?
int count = 0;
while (count < 3) {
cout << count++;
}
A.
012
B.
123
C.
0123
D.
333
Explanation & Key
Correct Answer:
10
In C++, what data types can be used as the condition variable in a switch statement?
A.
Only float and double
B.
Integral types (int, char, enum) and scoped enums
C.
Any type, including std::string and vector
D.
Only pointers
Explanation & Key
Correct Answer:
11
What is the output of the following code snippet?
int x = 1;
if (x > 0)
if (x < 1)
cout << "A";
else
cout << "B";
A.
A
B.
B
C.
Nothing is printed
D.
Compilation Error
Explanation & Key
Correct Answer:
12
What is the value of i after the following loop finishes?
int i;
for (i = 0; i < 10; i += 3) {}
cout << i;
A.
9
B.
10
C.
12
D.
11
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong