1/21
22 comprehensive flashcards for C++ midterm review, covering chapters 1 through 6, core syntax, functional logic, and exam traps.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the difference between a bit and a byte in computer memory?
A bit is the smallest piece of memory, holding a binary value of either 0 (off/false) or 1 (on/true). A byte consists of 8 consecutive bits and is identified by a unique memory address.
Explain the core difference between Procedural Programming and Object-Oriented Programming (OOP).
Procedural programming focuses on actions or processes where explicit functions are written to process data. Object-Oriented programming focuses on creating objects that encapsulate both data and the functions (methods) designed to manipulate that data.
What is the purpose of #include
\text{#include
What are the specific requirements and operational limits of the modulus (%) operator?
The modulus operator calculates the remainder left over from integer division (e.g., 13%5 evaluates to 3). Crucially, both operands must be integers; attempting to evaluate a floating-point value (such as 13%5.0) yields a compiler error.
How do you declare a named constant in C++, and what happens if code attempts to reassign it?
You define it by prepending the variable declaration with the const modifier keyword (e.g., \text{const double TAX_RATE} = 0.0675;). If any code downstream tries to reassign or change this value, the compiler stops and throws a read-only error.
How does the cin object handle chained variables, and why does input sequence matter?
You chain inputs together via standard extraction operators (e.g., cin>>height>>width;). The user enters sequential inputs separated by whitespace or lines. Order is critical because values match directly into parameters from left to right.
What is a program hand trace (desk check) and why is it used?
A hand trace is a debugging protocol where you manually track line-by-line statement execution, documenting structural variable changes in an index matrix or grid. It is executed to diagnose semantic logic errors prior to runtime.
What is the functional hazard of accidentally mistyping = instead of == inside a conditional test block?
== tests conditional logical equality, while = is an assignment command. Writing if (x = 10) reassigns x to 10. Because 10 evaluates as non-zero (true), the block executes unconditionally regardless of $$\text{x}$\'s previous state.
What happens inside a switch control block if a developer forgets to include a break; line at the end of a matched case?
The switch architecture undergoes full \"fall-through.\" Execution lines drop linearly into the statements of all subsequent case blocks below it, executing them without checking if their case constraints match, until a break or the closing bracket is reached.
Explain block/local variable scope boundaries and what occurs if names overlap across scope tiers.
Variables created within matching braces { } exist only from their point of creation down to that block\'s terminating brace. If an nested inner block redeclares a matching variable name, the outer variable becomes hidden/inaccessible inside that inner scope.
Contrast the execution differences between a standard while loop and a do-while loop structure.
A while loop acts as a pre-test loop, validating its conditional rule before entering the body (allowing 0 total runs). A do-while loop acts as a post-test loop, running the entire interior block first before verifying its state, guaranteeing at least 1 iteration.
Differentiate the side-effects of Prefix (++val) vs. Postfix (val++) processing inline.
Prefix arrays increment the variable data first, then evaluate/pass the freshly modified total into the active statement. Postfix arrays pass the current variable value to the statement first, and execute the addition step instantly afterward in memory.
Prior to modern C++11, what specialized file stream format was demanded by .open() and how do you parse standard strings to it?
Legacy versions require a null-terminated character array (a standard C-string). When utilizing a standard string variable, you must extract its underlying pointer layout using the \text{.c_str()} member method: \text{fileVariable.open(name.c_str());}.
What is a function prototype declaration statement and where should it be placed in source files?
A prototype reports the target signature name, returns, and variable requirements to the compiler before the execution block runs. It resides above main(), allowing developer flexibility to write comprehensive full definitions lower down.
Identify the processing differences between passing functional arguments by value vs. by reference (&).
Passing by value duplicates data into isolated sandboxed parameters, protecting the caller. Passing by reference (&) channels the actual variable location into the routine; any changes inside the function immediately and permanently overwrite the original variable.
What is function overloading and how does the compiler select the appropriate block to call?
Function overloading allows developers to instantiate multiple discrete functions sharing identical names, provided they maintain unique signature parameters. The compiler matches inputs against types, quantity, and sequential ordering to route calls.
Define the concepts of Stubs and Drivers within modular unit validation paradigms.
A Stub is a basic non-functional mockup routine that prints a diagnostic string or status to mirror incomplete features. A Driver is a short scaffolding routine composed explicitly to fire and inject varied data testing configurations into a target function.
True or False: Placing an accidental semicolon after an if, while, or for header produces a compilation failure.
False. The compiler perceives it as an intentional empty line execution, truncating the statement branch. This causes code to execute unconditionally or loops to run indefinitely. (Note: do-while loops are structurally required to end with a semicolon).
Trace results for: result = num1++ + --num2; given initial states num1 = 5, num2 = 5.
Mathematical inputs evaluate as 5 (the postfix un-incremented baseline of num1) combined with 4 (the prefix decremented state of num2), generating an output result of 9. Final values in memory are num1=6,num2=4.
How can you verify from a code script if an argument will sustain its mutations globally post-call?
Inspect the function prototype or method signature block. If an ampersand operator badge (&) is tracking alongside the argument type definition, it signals pass-by-reference execution, meaning internal edits permanently mutate the caller.
What data parameter rules exist for a switch expression test condition?
The processing parameter inside a switch statement must strictly resolve into a distinct discrete integral value (such as int, char, or enum types). Passing decimal floats or double precisions halts building and flags a syntax failure.
Explain short-circuit evaluation rules and their potential operational bugs.
If the left-side condition fulfills or refutes the expression logic completely, the runtime skips compiling the right-side statement entirely. (For &&: a false left stops; for ||: a true left stops). If the skipped right side contains a mutating flag like x++, it never runs.