1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Selection control structure
A structure that chooses which set of statements to execute based on a condition.
Control structure effect on program flow
Alters the normal sequential flow by allowing decisions and repetitions.
Correct syntax of an if-else statement
if (condition) { / code / } else { / code / }
Relational operators (comparison)
==, !=, <, >, <=, >=
Logical (Boolean) operators
&& (AND), || (OR), ! (NOT)
Order of precedence (highest to lowest)
! > && > ||
Short Circuit Evaluation
The process where evaluation stops as soon as the result is known (e.g., in false && ..., the rest is skipped).
Conditional operator syntax (?:)
condition ? value_if_true : value_if_false;
Switch statement syntax
switch (expression) { case value1: / code /; break; case value2: / code /; break; default: / code /; }
Reserved words in switch
switch, case, break, default
Nested control structure
A control structure inside another, e.g., if inside a for loop.
Does if (x = 5) check equality?
No, it assigns 5 to x. Use == for equality.
Can switch evaluate strings in standard C++?
No, only integral types like int and char.
Logical NOT precedence
Higher than && and ||
Purpose of break in switch
Exits the switch block to prevent fall-through.
What does this print? cout << ((a < b) ? "Yes" : "No");
Yes (if a = 3, b = 4)
What does this print? int choice = 2; switch (choice) { case 1: cout << "One"; break; case 2: cout << "Two"; case 3: cout << "Three"; break; default: cout << "Other"; }
TwoThree (no break after case 2)