Computer Science & Programming: Decision Making, Loops, and Functions

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/86

flashcard set

Earn XP

Description and Tags

Comprehensive vocabulary flashcards covering decision-making structures, loops, functions, and scoping rules in C++.

87 Terms

1
New cards

ASCII (American Standard Code for Information Interchange)

A character encoding standard that converts characters into numeric binary codes, supporting 128128 characters in C++, including uppercase letters (6565 through 9090), lowercase letters (9797 through 122122), numeric characters (4848 through 5757), and the null character (00).

2
New cards

Relational Operators

Operators (>>, <<, >=>=, <=<=, ====, !=!=) used to compare numeric and character values to determine their relative order, producing a Boolean result of true (11) or false (00).

3
New cards

Flag

A variable, typically defined as a bool or an int, that signals whether a specific condition currently exists in a program, where 00 represents false and any non-zero value represents true.

4
New cards

Trailing else

The final else clause in an if/else if sequence that provides a default action when none of the preceding relational conditions evaluate to true.

5
New cards

Short-Circuit Evaluation

The evaluation rule where the second operand of a logical operator (&&\&\& or ∣∣||) is skipped if the first operand is sufficient to determine the truth value of the entire expression.

6
New cards

Block Scope

The lifetime and visibility of a variable defined inside braces ({}\{ \}), extending strictly from its point of definition to the closing brace of that block.

7
New cards

cctype Functions

A C++ character classification library providing functions such as isalpha, isdigit, islower, isupper, isspace, isalnum, isprint, and ispunct to test the category of a character.

8
New cards

Conditional Operator

A ternary operator formatted as ? :?\,: that evaluates a condition and returns the value of one of two subexpressions depending on whether the condition evaluates to true or false.

9
New cards

switch Statement

A multi-way branching statement that compares an integer or character expression against multiple constant case labels to determine which group of statements to execute.

10
New cards

break Statement

A control statement used to terminate execution in a switch structure to prevent fall-through, or to terminate and exit early from the body of a loop.

11
New cards

Pretest Loop

A loop structure, such as a while loop or for loop, that tests its controlling expression prior to executing the body; if initially false, the loop body executes 00 times.

12
New cards

Post-test Loop

A loop structure, specifically the do-while loop, that evaluates its condition after the body executes, guaranteeing that the body executes at least 11 time.

13
New cards

Counter

A variable incremented or decremented on each iteration of a loop, typically initialized prior to the loop and used to control repetition.

14
New cards

Sentinel

A special terminal value in an input sequence that signals the end of input data and cannot be mistaken for valid input (such as −1-1 or −999-999).

15
New cards

Infinite Loop

A loop that fails to exit because its condition never evaluates to false, often caused by omitting the increment or update step inside the loop body.

16
New cards

Nested Loop

A loop placed entirely inside the body of an outer loop, where the inner loop executes all of its iterations for every single iteration of the outer loop.

17
New cards

continue Statement

A control statement that halts the current loop iteration and jumps immediately to the update step in a for loop or the condition evaluation in a while or do-while loop.

18
New cards

Modular Programming

A software design technique that divides a program into smaller, manageable functions to simplify coding and improve program maintainability.

19
New cards

Function Prototype

A declaration placed before function calls that notifies the compiler of the function name, return type, and parameter data types, terminated by a semicolon.

20
New cards

Function Header

The initial line of a function definition that specifies the return type, the function name, and the parameter list with parameter names, containing no terminating semicolon.

21
New cards

Pass by Value

A parameter passing mechanism where a copy of an argument value is transferred into the parameter variable, protecting the original variable from modification.

22
New cards

Reference Variable

An alias for another variable defined with an ampersand (&\&); when used as a parameter, modifications made to it directly alter the original argument variable.

23
New cards

Static Local Variable

A local variable declared with the static keyword that is initialized only once during the initial function call and retains its value between subsequent calls.

24
New cards

Variable Shadowing

A condition where a local variable declared in an inner block or function has the same identifier as an outer or global variable, hiding the outer variable within that block.

25
New cards

Function Signature

The unique combination of a function's identifier name and the ordered sequence of its parameter types, excluding the return type.

26
New cards

Overloaded Functions

Two or more functions sharing the same name but having different signatures (parameter types or number of parameters), resolved by the compiler at the point of call.

27
New cards

Recursion

A process in which a function calls itself directly or indirectly to solve a problem until reaching a terminating base condition.

28
New cards

ASCII Character Encoding Scheme

A 7-bit character encoding system that maps individual characters to numeric codes spanning 00 through 127127 (128128 total characters supported in standard C++), where uppercase letters range from 6565 through 9090, lowercase letters range from 9797 through 122122, numeric digits range from 4848 through 5757, and the null character is represented by 00.

29
New cards

Relational Operator Hierarchy and Output

A group of comparison operators where relational order operators (>>, >=>=, <<, <=<=) hold higher precedence than equality operators (====, !=!=), all evaluating strictly to a Boolean result of true (11) or false (00).

30
New cards

Short-Circuit Evaluation in C++

A compiler evaluation rule where the right operand of a logical expression is skipped completely if the left operand is sufficient to determine the final truth value: if the first operand is false in an &&\&\& expression, or true in a ∣∣|| expression.

31
New cards

Code Output: Logical and Relational Precedence with cout << (2 < 3 || 5 > 6 && 7 > 8);

Outputs 11 because relational comparisons execute first, followed by logical AND (&&\&\&) due to higher precedence than logical OR (∣∣||), simplifying the expression to (1  ∣∣  0)(1 \; || \; 0), which evaluates to true (11).

32
New cards

Conditional (Ternary) Operator Syntax and Function

A three-operand operator formatted as condition  ?  expression1  :  expression2\text{condition} \; ? \; \text{expression1} \; : \; \text{expression2}, which evaluates the condition and executes or returns the value of expression1\text{expression1} if true, or expression2\text{expression2} if false.

33
New cards

Code Output: Ternary Operator Evaluation with int age = 17; cout << (age >= 18 ? "Adult" : "Minor");

Prints Minor because the condition age>=18age >= 18 evaluates to false (17>=1817 >= 18 is false), prompting the conditional operator to select the subexpression following the colon.

34
New cards

The switch Statement Execution and the break Keyword

A multi-way branching statement that compares an integral expression against constant case values, where the omission of a break statement results in fall-through, causing execution to continue sequentially through following cases regardless of their labels.

35
New cards

Code Output: switch Statement Fall-Through Trace

When grade = 'B' is evaluated in a switch block containing case 'B': cout << "Good"; without a break, followed immediately by case 'C': cout << "Average"; break;, it prints GoodAverage because control falls directly into the next case.

36
New cards

Fundamental Difference: Pretest Loops vs. Post-Test Loops

Pretest loops (such as while and for) evaluate their condition prior to entering the loop body and may execute 00 times, whereas post-test loops (do-while) evaluate the condition after body execution, guaranteeing at least 11 iteration.

37
New cards

Code Output: Postfix Increment Evaluation with int a = 2, b = 5; int c = a * b++;

Assigns 1010 to variable cc and updates bb to 66, because postfix increment uses the current value of bb (55) in the multiplication before incrementing bb in memory.

38
New cards

Sentinel Value in Loop Control

A distinctive dummy value placed in an input sequence to signal the completion of data entry and terminate the loop, chosen specifically so it cannot be mistaken for valid input data (e.g., using −1-1 or −999-999 for non-negative scores).

39
New cards

Code Tracing: Nested Loop Execution Count for for(int i=0; i<3; i++) for(int j=0; j<2; j++) count++;

Increments count a total of 66 times, because the inner loop executes its full cycle of 22 iterations for every single one of the 33 iterations of the outer loop (3×2=63 \times 2 = 6).

40
New cards

Control Flow Distinction: break vs. continue in Loops

The break statement terminates the innermost loop entirely and jumps to the code following the loop structure, whereas continue halts only the current iteration, jumping directly to the loop's update step (for) or condition test (while/do-while).

41
New cards

Architectural Distinction: Function Prototype vs. Function Header

A function prototype is a declaration ending with a semicolon placed before function calls to alert the compiler of the function's name, return type, and parameter types, whereas a function header is the first line of the actual function definition containing parameter names and no semicolon.

42
New cards

Parameter Passing Mechanisms: Pass by Value vs. Pass by Reference

Pass by value transfers an isolated copy of the argument into the parameter, preventing changes to the original variable, whereas pass by reference (using &\&) transfers an alias bound directly to the argument, allowing the function to modify the caller's variable.

43
New cards

Code Output: Pass by Reference with void test(int &x) { x += 5; } int main() { int n = 10; test(n); cout << n; }

Displays 1515 because parameter xx is declared as a reference variable (&x\&x), causing modifications made to xx inside test to directly alter the memory location of nn in main.

44
New cards

Static Local Variable Behavior and Lifetime

A local variable declared with the static keyword that is initialized only once upon the first function invocation and retains its value between subsequent calls across the entire execution of the program.

45
New cards

Variable Shadowing in Nested Blocks and Functions

A condition occurring when a local variable declared inside an inner block or function shares the exact same name as an outer or global variable, rendering the outer variable inaccessible and hidden within the boundaries of that inner block.

46
New cards

Function Signature and Overloading Resolution

A function signature consists exclusively of the function name and the ordered data types in its parameter list (excluding the return type); overloaded functions share a name but feature distinct signatures, enabling the compiler to invoke the matching version.

47
New cards

Code Output: Static Local Variable Accumulation in Loops

Calling a function containing static int c = 0; c++; cout << c << " "; three times in a loop prints 1 2 3 because the static variable c preserves its incremented value between successive function calls rather than re-initializing.

48
New cards

ASCII Character Encoding Standard

A 7-bit character encoding standard that maps characters to numeric binary codes, supporting 128128 discrete characters in C++ ranging from 00 to 127127, where uppercase letters span 6565 through 9090, lowercase letters span 9797 through 122122, numeric digits span 4848 through 5757, and the null terminator is represented by 00.

49
New cards

Underlying Representation of char in C++

An 88-bit (11-byte) integer data type providing 256256 total values (00 through 255255) that follows standard integer rules and converts to visible characters by decoding numeric values via character sets like ASCII.

50
New cards

Relational Operators

Comparison operators (>>, <<, >=>=, <=<=, ====, !=!=) evaluated from left to right that determine the relative order or equality of two operands, strictly producing a Boolean integer result of true (11) or false (00).

51
New cards

Assignment Operator vs. Equality Operator

The single equals sign (==) assigns the evaluated value of the right-hand operand to the variable on the left, whereas the double equals sign (====) compares two expressions for equivalence without altering values, evaluating to true (11) or false (00).

52
New cards

Flag Variable

A variable, typically declared as a bool or an int, used to signal whether a specific condition currently exists in a program, where an evaluated value of 00 represents false and any non-zero value represents true.

53
New cards

Trailing else Clause

The final else statement in an if/else if sequence that provides a default action executed only when all preceding relational test conditions evaluate to false.

54
New cards

Short-Circuit Evaluation

An evaluation rule where the second operand of a logical expression is skipped completely if the first operand is sufficient to determine the overall truth value: when the first operand is false in an &&\&\& expression, or true in a ∥∥\|\| expression.

55
New cards

Logical Operator Precedence Hierarchy

The strict order of evaluation among logical operators where logical NOT (!!) holds the highest precedence, followed by logical AND (&&\&\&), and finally logical OR (∥∥\|\|) with the lowest precedence.

56
New cards

Block Scope

The visibility and lifetime of an identifier defined within curly braces ({}\{ \}), extending strictly from its point of declaration to the closing brace of that block, after which the identifier is destroyed.

57
New cards

Variable Shadowing

A scenario where a local variable declared in an inner block or function has the same identifier name as an outer or global variable, hiding the outer variable and making it inaccessible within that inner scope.

58
New cards

cctype Character Classification Functions

A C++ library providing functions such as isalpha, isdigit, islower, isupper, and isspace that test the character category of a char argument and return a non-zero integer for true or 00 for false.

59
New cards

Conditional (Ternary) Operator

A three-operand operator formatted as condition ? expression1 : expression2 that evaluates a Boolean condition and executes or returns the value of expression1 if true, or expression2 if false.

60
New cards

The switch Statement

A multi-way branching statement that compares the value of an integer or character expression against constant integral case labels to determine which group of statements to execute.

61
New cards

Fall-Through Behavior in switch Structures

The sequential execution of statements in subsequent case blocks that occurs when a matching case lacks a terminating break statement, continuing until a break or the end of the switch is reached.

62
New cards

Pretest Loops vs. Post-Test Loops

Pretest loops (while and for) evaluate their condition before the loop body executes and may run 00 times, whereas post-test loops (do-while) evaluate the condition after the body executes, guaranteeing at least 11 execution.

63
New cards

Increment and Decrement Operators: Prefix vs. Postfix Mode

Prefix mode (++var, --var) modifies the variable first and returns the updated value to the expression, while postfix mode (var++, var--) yields the current value to the expression before modifying the variable in memory.

64
New cards

Counter Variable

A variable incremented or decremented by a fixed value on each iteration of a loop, typically initialized prior to loop entry and used as a loop control variable to govern repetition.

65
New cards

Sentinel Value

A distinctive terminal value placed in an input sequence that signals the end of input data and terminates a loop, chosen specifically so that it cannot be confused with valid, legitimate data (such as −1-1 or −999-999).

66
New cards

Infinite Loop

A loop structure that continues executing indefinitely because its controlling test condition never evaluates to false, frequently caused by omitting the counter update step inside the loop body.

67
New cards

Nested Loops

A loop placed entirely inside the body of an outer loop, where the inner loop executes its complete set of iterations for every single iteration performed by the outer loop.

68
New cards

The break Statement vs. The continue Statement in Loops

The break statement terminates the innermost loop immediately and transfers control out of the loop, whereas continue skips the rest of the current iteration and jumps directly to the condition test or update step.

69
New cards

Modular Programming

A software design approach that divides a large program into smaller, manageable, and independent functions, simplifying code authoring, debugging, testing, and long-term maintenance.

70
New cards

Function Prototype vs. Function Header

A function prototype is a declaration ending with a semicolon placed before function calls to inform the compiler of the function's interface, whereas a function header is the first line of the actual function definition without a semicolon.

71
New cards

Pass by Value Mechanism

A parameter-passing mechanism where a copy of the argument value is passed into the function parameter, ensuring that any modifications made to the parameter do not affect the caller's original variable.

72
New cards

Pass by Reference Mechanism

A parameter-passing mechanism where an ampersand (&\&) declares a parameter as an alias for the argument variable, allowing the function to directly access and modify the variable in the calling environment.

73
New cards

Static Local Variable

A local variable declared with the static keyword that is initialized only once upon the first function invocation and retains its value between subsequent function calls throughout program execution.

74
New cards

Global Variable vs. Global Constant

A global variable is defined outside all functions and can be modified anywhere in the file (defaulting to 00 or null), whereas a global constant uses the const qualifier to create a read-only value accessible to all functions.

75
New cards

Function Signature and Function Overloading

A function signature consists of the function name and the ordered data types of its parameters (excluding the return type); function overloading allows multiple functions to share a name if their signatures differ.

76
New cards

Code Output: Logical Precedence in cout &lt;&lt; (2 &lt; 3 || 5 &gt; 6 &amp;&amp; 7 &gt; 8);

Outputs 11 because relational operators evaluate first, simplifying to (1  ∥∥  0  &&  0)(1 \; \|\| \; 0 \; \&\& \; 0); then logical AND evaluates before logical OR, yielding (1  ∥∥  0)(1 \; \|\| \; 0), which evaluates to true (11).

77
New cards

Code Output: Postfix Increment Multiplication with int a = 2, b = 5; int c = a * b++;

Assigns 1010 to variable cc and updates bb to 66, because postfix increment evaluates the multiplication using bb's current value (55) before incrementing bb in memory.

78
New cards

Code Output: Nested Loop Iteration Count with for(int i = 0; i &lt; 3; i++) for(int j = 0; j &lt; 2; j++) count++;

Increments count a total of 66 times, because the inner loop executes its full cycle of 22 iterations for every single one of the 33 iterations of the outer loop (3×2=63 \times 2 = 6).

79
New cards

Code Output: Switch Fall-Through with case 'B': cout &lt;&lt; "Good";

Prints GoodAverage when grade = 'B' because case 'B' contains no terminating break statement, causing execution to fall through into case 'C': cout &lt;&lt; "Average"; break;.

80
New cards

Code Output: Pass by Reference with void test(int &amp;x) { x += 5; } int main() { int n = 10; test(n); cout &lt;&lt; n; }

Displays 1515 because parameter xx is declared as a reference variable (&x\&x), causing modifications made to xx inside test to directly alter the memory location of nn in main.

81
New cards

Code Output: Static Local Variable Accumulator with static int c = 0; c++; cout &lt;&lt; c &lt;&lt; " ";

Prints 1 2 3 when called three times in a loop because the static local variable c preserves its incremented value across successive function calls rather than re-initializing.

82
New cards

Code Output: While Loop Accumulator with int day = 1; while(day &lt;= 3) { total += 10; day++; }

Results in total being incremented by 3030 because the loop executes exactly 33 iterations (when day is 11, 22, and 33), adding 1010 on each pass before terminating when day reaches 44.

83
New cards

Code Output: Character Arithmetic and Conversion with cout &lt;&lt; static_cast&lt;char&gt;(65 + 2);

Displays C because in the ASCII encoding scheme, numeric code 6565 corresponds to character 'A', so adding 22 evaluates to 6767, which represents 'C' when cast to char.

84
New cards

Code Output: Short-Circuit Evaluation Side Effects with int x = 1, y = 0; if (x++ &amp;&amp; y++) cout &lt;&lt; x &lt;&lt; y; else cout &lt;&lt; y &lt;&lt; x;

Displays 12 because x++ evaluates to 11 (true) and increments x to 22, prompting evaluation of y++ which evaluates to 00 (false) and increments y to 11; the else branch executes printing y (11) then x (22).

85
New cards

Code Output: Nested If Dangling Else Resolution with if (a &gt; b) if (a &gt; 0) cout &lt;&lt; "X"; else cout &lt;&lt; "Y"; else cout &lt;&lt; "Z";

When a=2a = 2 and b=5b = 5, it outputs Z because the condition a &gt; b (2>52 > 5) evaluates to false, causing execution to jump directly to the outer matching else branch.

86
New cards

Code Output: Prefix vs. Postfix Decrement with int a = 5; while (a-- &gt; 0) cout &lt;&lt; a;

Prints 43210 because a-- &gt; 0 tests the current value of a before decrementing it, so on the first iteration it tests 5>05 > 0 (true) and prints the decremented value 4, continuing until testing 0>00 > 0 (false).

87
New cards

Code Output: Function Default Arguments with int add(int a, int b = 2, int c = 3) { return a + b + c; } cout &lt;&lt; add(1);

Outputs 66 because passing only one argument assigns a=1a = 1, while parameters b and c utilize their default argument values of 22 and 33, summing to 1+2+3=61 + 2 + 3 = 6.