Free Online Flashcard Deck

3 Selection and Control Structures Free Online FlashCards

Study 3 Selection and Control Structures with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What does a C++ selection condition evaluate to?

Back

A condition is an expression contextually converted to bool. true selects the true branch; false selects the false branch.

02
Front

Which operator tests equality in C++?

Back

The equality comparison operator is ==. The single = operator assigns a value instead of testing equality.

03
Front

How are numeric expressions converted to bool?

Back

Zero converts to false, while any nonzero numeric value converts to true.

04
Front

Which operator means logical AND, and when is its right operand evaluated?

Back

The logical AND operator is &&. With A && B, B is evaluated only when A is true.

05
Front

Why can direct floating-point equality be unreliable?

Back

Use a tolerance such as std::abs(a - b) < 0.000001, because many decimal fractions cannot be represented exactly in binary floating-point.

06
Front

When does an if block execute?

Back

An if statement executes its statement or block only when its condition is true.

07
Front

What happens in an if-else statement?

Back

Only one branch executes: the if branch when its condition is true, or the else branch when it is false.

08
Front

How does an else-if chain choose a branch?

Back

An else-if chain selects the first true condition, so the order of conditions matters.

09
Front

How can braces prevent a dangling else?

Back

Use braces to make each intended block explicit and prevent a dangling else from attaching to the wrong if.

10
Front

When is switch preferable to a long else-if chain?

Back

Use switch when one integral or enumeration expression is compared with several fixed constant values.

11
Front

What does break do in a switch statement?

Back

A break exits the switch. Without it, execution continues into the following case, causing fallthrough.

12
Front

What happens when no switch case matches?

Back

A switch can use default when no case matches. If default is absent, execution continues after the switch.