True or false: In C++, using the integer expression 0 as the condition of an if statement selects the false branch.
3 Selection and Control Structures Online Quiz Questions
Use this free practice quiz with 20 questions to review 3 Selection and Control Structures, test your knowledge, and prepare for your next test or exam.
Given the condition A || B, when is B evaluated under C++ short-circuit evaluation?
- A
Bis always evaluated beforeA - B
Bis evaluated only ifAis false - C
Bis evaluated only ifAis true - D
Neither operand is evaluated if
Ais false
Which C++ logical operator reverses a Boolean condition, such as changing finished to its opposite value?
Complete the statement: In an if/else structure, the block executes when the if condition is false.
Select all situations for which a C++ switch statement is an appropriate choice.
- A
Selecting among fixed menu values stored in an integer
- B
Testing whether a score is within a range such as 80 through 89
- C
Selecting among fixed values of an enumeration
- D
Combining unrelated conditions such as
isAdmin && hasId
Complete the statement: If no case matches the switch expression and a fallback label is present, control transfers to .
What is the maximum number of default labels allowed in one C++ switch statement?
Select all statements that correctly describe break and fallthrough in a C++ switch statement.
- A
Executing
breakexits theswitchstatement - B
Omitting
breakautomatically exits after the current case - C
Omitting
breakcan cause execution to continue into the next case - D
A
breakchanges the value of the switch expression
What is the primary purpose of the C++ conditional operator ?:?
- A
It always evaluates both value alternatives and returns their sum
- B
It executes a sequence of statements in both branches
- C
It selects one of two values based on a condition
- D
It compares two values and returns a Boolean result
Explain when a C++ programmer should choose if or an if/else if chain, switch, or the conditional operator ?:. Include one reason not to use a deeply nested conditional expression.
What happens when C++ evaluates if (value = 5) rather than if (value == 5)?
- A
It compares
valuewith 5 and enters the branch only if they are equal - B
It assigns 5 to
value, then the resulting nonzero value makes the condition true - C
It produces a compilation error because assignment cannot appear in a condition
- D
It assigns 0 to
valuebecause=is the equality operator
True or false: Direct equality comparison of floating-point values can be unreliable because many decimal fractions cannot be represented exactly in binary floating-point.
- A
True
- B
False
Given int count = 0;, what happens when the program executes if (count) { std::cout << "There are items\n"; }?
- A
The message is printed because every integer is true.
- B
The message is not printed because zero converts to
false. - C
The program fails to compile because
countis not abool. - D
The message is printed only when
countis negative.
True or false: In the expression A && B, B is evaluated only if A is true.
- A
True
- B
False
What is the effect of executing if (value = 5) { ... } in C++?
- A
It tests whether
valueis equal to5. - B
It always makes the condition false.
- C
It assigns
5tovalue, and the nonzero result makes the condition true. - D
It produces a compilation error because assignments cannot appear in conditions.
Which C++ selection construct is designed to compare one integral or enumeration expression with several fixed constant values?
What value is assigned to grade by this code when score is 95? if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else { grade = 'F'; }
- A
gradebecomes'A'. - B
gradebecomes'B'because 95 is also at least 80. - C
graderemains uninitialized. - D
All matching branches execute in sequence.
What C++ operator compactly selects one of two values based on a condition, as in age >= 18 ? "adult" : "minor"?
What output is produced by the switch statement when option has the value 4 and the statement contains cases 1, 2, and 3 plus a default that prints Unknown option?
- A
Starting - B
Settings - C
Unknown option - D
Nothing, because a switch must always have a matching case
Which selection structure is the clearest choice for assigning grades based on ranges such as score >= 90, score >= 80, and score >= 70?
- A
A
switchwith a case for every possible score - B
An
if/else ifchain - C
A conditional expression with several nested
?:operators - D
A
switchusingscore >= 90as a case label
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.