Free Practice Quiz Question List

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.

20 questions
01
True or false
1 point

True or false: In C++, using the integer expression 0 as the condition of an if statement selects the false branch.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Given the condition A || B, when is B evaluated under C++ short-circuit evaluation?

  1. A

    B is always evaluated before A

  2. B

    B is evaluated only if A is false

  3. C

    B is evaluated only if A is true

  4. D

    Neither operand is evaluated if A is false

03
Written response
1 point

Which C++ logical operator reverses a Boolean condition, such as changing finished to its opposite value?

04
Fill in the blank
1 point

Complete the statement: In an if/else structure, the block executes when the if condition is false.

05
Choose all
1 point

Select all situations for which a C++ switch statement is an appropriate choice.

  1. A

    Selecting among fixed menu values stored in an integer

  2. B

    Testing whether a score is within a range such as 80 through 89

  3. C

    Selecting among fixed values of an enumeration

  4. D

    Combining unrelated conditions such as isAdmin && hasId

06
Fill in the blank
1 point

Complete the statement: If no case matches the switch expression and a fallback label is present, control transfers to .

07
Written response
1 point

What is the maximum number of default labels allowed in one C++ switch statement?

08
Choose all
1 point

Select all statements that correctly describe break and fallthrough in a C++ switch statement.

  1. A

    Executing break exits the switch statement

  2. B

    Omitting break automatically exits after the current case

  3. C

    Omitting break can cause execution to continue into the next case

  4. D

    A break changes the value of the switch expression

09
Choose one
1 point

What is the primary purpose of the C++ conditional operator ?:?

  1. A

    It always evaluates both value alternatives and returns their sum

  2. B

    It executes a sequence of statements in both branches

  3. C

    It selects one of two values based on a condition

  4. D

    It compares two values and returns a Boolean result

10
Open ended
1 point

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.

11
Choose one
1 point

What happens when C++ evaluates if (value = 5) rather than if (value == 5)?

  1. A

    It compares value with 5 and enters the branch only if they are equal

  2. B

    It assigns 5 to value, then the resulting nonzero value makes the condition true

  3. C

    It produces a compilation error because assignment cannot appear in a condition

  4. D

    It assigns 0 to value because = is the equality operator

12
True or false
1 point

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.

  1. A

    True

  2. B

    False

13
Choose one
1 point

Given int count = 0;, what happens when the program executes if (count) { std::cout << "There are items\n"; }?

  1. A

    The message is printed because every integer is true.

  2. B

    The message is not printed because zero converts to false.

  3. C

    The program fails to compile because count is not a bool.

  4. D

    The message is printed only when count is negative.

14
True or false
1 point

True or false: In the expression A && B, B is evaluated only if A is true.

  1. A

    True

  2. B

    False

15
Choose one
1 point

What is the effect of executing if (value = 5) { ... } in C++?

  1. A

    It tests whether value is equal to 5.

  2. B

    It always makes the condition false.

  3. C

    It assigns 5 to value, and the nonzero result makes the condition true.

  4. D

    It produces a compilation error because assignments cannot appear in conditions.

16
Written response
1 point

Which C++ selection construct is designed to compare one integral or enumeration expression with several fixed constant values?

17
Choose one
1 point

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'; }

  1. A

    grade becomes 'A'.

  2. B

    grade becomes 'B' because 95 is also at least 80.

  3. C

    grade remains uninitialized.

  4. D

    All matching branches execute in sequence.

18
Written response
1 point

What C++ operator compactly selects one of two values based on a condition, as in age >= 18 ? "adult" : "minor"?

19
Choose one
1 point

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?

  1. A

    Starting

  2. B

    Settings

  3. C

    Unknown option

  4. D

    Nothing, because a switch must always have a matching case

20
Choose one
1 point

Which selection structure is the clearest choice for assigning grades based on ranges such as score >= 90, score >= 80, and score >= 70?

  1. A

    A switch with a case for every possible score

  2. B

    An if/else if chain

  3. C

    A conditional expression with several nested ?: operators

  4. D

    A switch using score >= 90 as a case label