Free Practice Quiz Question List

03 Conditional Control Structures Online Quiz Questions

Use this free practice quiz with 20 questions to review 03 Conditional Control Structures, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What does this C++ code print? int x = 12; if (x > 15) { std::cout << "large"; } else if (x > 10) { std::cout << "medium"; } else { std::cout << "small"; }

  1. A

    small

  2. B

    medium

  3. C

    large

  4. D

    invalid

02
True or false
1 point

True or false: In a nested C++ conditional, an else belongs to the nearest preceding unmatched if, unless braces establish a different statement structure.

  1. A

    True

  2. B

    False

03
Fill in the blank
1 point

In C++, when an arithmetic expression with value zero is used as a condition, it is interpreted as .

04
Written response
1 point

What C++ keyword phrase introduces an additional condition between an if branch and a final else branch?

05
Choose one
1 point

Which approach is most appropriate for testing whether an integer value lies between 1 and 10, inclusive?

  1. A

    Use switch with a case for every possible value in the range.

  2. B

    Use switch with the condition value >= 1 && value <= 10.

  3. C

    Use if with a compound range condition.

  4. D

    Use switch because ranges are discrete constant values.

06
Choose all
1 point

Select all correct statements about the short-circuit behavior of C++ logical operators.

  1. A

    In A && B, B is not evaluated when A is false.

  2. B

    In A || B, B is not evaluated when A is true.

  3. C

    denominator != 0 && numerator / denominator > 2 can prevent division when the denominator is zero.

  4. D

    In A && B, both operands are always evaluated before the result is known.

07
True or false
1 point

True or false: In a C++ switch, reaching a case label automatically exits the switch after that case's statements execute.

  1. A

    True

  2. B

    False

08
Fill in the blank
1 point

To normally stop execution after a matching case in a C++ switch, place the keyword at the end of that case.

09
Written response
1 point

Which C++ logical operator should connect age >= 18 and has_permission when entry requires both adulthood and permission?

10
Choose all
1 point

Consider a rule that permits entry only when age >= 18 and has_ticket is true. Select all statements that correctly apply nested and compound conditional logic to this rule.

  1. A

    With age = 17 and has_ticket = true, age >= 18 && has_ticket is false.

  2. B

    A nested test can check has_ticket only after age >= 18 succeeds.

  3. C

    A compound condition can express the two required tests as age >= 18 && has_ticket.

  4. D

    With age = 17 and has_ticket = true, the nested version must print Enter the event.

11
Choose one
1 point

Which condition correctly implements this rule: a learner satisfies the requirement if the score is at least 60 and attendance is at least 75, or the learner has special permission?

  1. A

    score >= 60 || attendance >= 75 || has_special_permission

  2. B

    (score >= 60 && attendance >= 75) || has_special_permission

  3. C

    score >= 60 && (attendance >= 75 || has_special_permission)

  4. D

    (score >= 60 || attendance >= 75) && has_special_permission

12
Choose one
1 point

Which declaration provides a character selector expression suitable for a C++ switch statement?

  1. A

    char command = 's'

  2. B

    double temperature = 21.5

  3. C

    std::string command = "save"

  4. D

    bool is_ready = true

13
Choose one
1 point

Consider the condition denominator != 0 && numerator / denominator > 2. If denominator is 0, what happens when C++ evaluates this condition?

  1. A

    The program always divides by zero.

  2. B

    The division is skipped.

  3. C

    The program must throw an exception.

  4. D

    The right side is evaluated before the left side.

14
Choose one
1 point

What happens in this C++ code? int x = -3; if (x) { /* body */ }

  1. A

    The body does not execute because x is not Boolean.

  2. B

    The body executes because -3 is nonzero.

  3. C

    The body executes only when x equals 1.

  4. D

    The program is ill-formed because if requires a comparison.

15
True or false
1 point

True or false: In C++, a < b < c means the same thing as a < b && b < c.

  1. A

    True

  2. B

    False

16
Choose one
1 point

What does this code print when logged_in is false and is_admin is true?

if (logged_in) {
if (is_admin) {
std::cout << "Administrator\n";
} else {
std::cout << "Not logged in\n";
}
} else {
std::cout << "Not logged in\n";
}

  1. A

    Administrator

  2. B

    A ticket is required.

  3. C

    Not logged in

  4. D

    Nothing is printed.

17
Written response
1 point

Which C++ operator should replace OP to execute the body only when is_closed is false? if (OPis_closed) { /* body */ }

18
Choose one
1 point

What value is assigned to grade when score is 95? if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else if (score >= 70) { grade = 'C'; } else { grade = 'F'; }

  1. A

    B

  2. B

    A

  3. C

    C

  4. D

    F

19
Written response
1 point

In this switch, how many case labels lead to the output Summer? switch (month) { case 6: case 7: case 8: std::cout << "Summer\n"; break; default: std::cout << "Another season\n"; }

20
Open ended
1 point

A C++ program contains this condition: if (x = 5) { ... }. Explain what the condition actually does, why its body executes when reached, and rewrite it to test whether x is equal to 5.