1/26
Comprehensive vocabulary flashcards covering key C++ concepts from the CS1120 Midterm 2 theory review.
Function
A construct that organizes code into reusable tasks (e.g., calling one via int result = Square(5);).
Pass by Value (int x)
A parameter-passing mechanism where the function gets a copy of the argument, leaving the original variable unchanged.
Pass by Reference (int& x)
A parameter-passing mechanism where the function receives the original variable directly and can modify it.
const vector
A parameter declaration specifying that the function reads the vector without copying it (&) and without changing it (const).
Default Parameters
Function parameters assigned fallback values that must be placed as the rightmost parameters (e.g., void Show(int x, int y = 5); is correct; void Show(int x = 5, int y); is wrong).
Function Overloading
Defining multiple functions with the same name but different parameter lists (different numbers or types). Differing only in return type or only in parameter names is not valid.
Header File (.h) vs. Source File (.cpp)
Declarations are placed in .h files and definitions in .cpp files; main.cpp uses #include "functions.h" and never includes the .cpp file.
Scope of a Local Variable
The boundary within which a local variable is accessible, limited strictly to inside the function where it is declared.
2D Array Indexing
Accessing elements in a two-dimensional array using grid[row][col] with 0-based indices (e.g., given int g[2][2] = {{3,5},{7,9}};, g[1][0] evaluates to 7).
v.push_back(x) and v.size()
Basic vector member functions where v.push_back(x) adds an element or object (such as students.push_back(s1);) to the end, and v.size() returns the element count.
Class vs. Object
A class serves as the blueprint, whereas an object is a concrete instance of that class (instantiated via Student s1;).
Constructor
A special member function that initializes an object, sharing the same name as the class, having no return type, and running automatically upon creation (e.g., default: Box b; parameterized: Box b(5);).
Private Data Members
Variables kept private within a class to provide controlled access through public member functions, such as getters to read values and setters to validate and write values.
Member Function Calling Syntax
Invoking a member function on an object using the dot operator (book.Print();) or on a pointer using the arrow operator (ptr->Print();).
Address-of Operator (&x)
An operator that evaluates to the memory address of variable x.
Dereference Operator (*p)
An operator that retrieves the value stored at the memory address pointed to by pointer p.
nullptr
A keyword representing a pointer that points to nothing, which must never be dereferenced.
Dynamic Memory Allocation and Deallocation
Allocating memory dynamically using new and freeing it using delete (e.g., int* p = new int; then delete p;), or using delete[] for dynamically allocated arrays (int* arr = new int[5]; then delete[] arr;).
Memory Leak
Dynamically allocated memory that can no longer be accessed by a program but has not been released.
Dangling Pointer
A pointer pointing to an object whose lifetime has ended (such as after delete). Setting p = nullptr; after deletion is a good practice to prevent it.
cin >> vs. getline()
Input methods where cin >> s stops extracting upon encountering whitespace, while getline(cin, line); reads the entire line including spaces.
File I/O Workflow
The standard sequence for handling files using ifstream (to read) and ofstream (to write): open -> check it opened -> stream data (inFS >> x; or outFS << x;) -> close().
istringstream
A stream class used to read and extract values from an existing string.
ostringstream
A stream class that stores formatted output inside a string, which can be retrieved using .str().
class Dog : public Animal
Inheritance syntax denoting that Dog derives from Animal, meaning Animal is the base class, Dog is the derived class, and Dog can use Animal's public members.
Recursive Function
A function that calls itself, requiring a base case to stop execution and recursive calls that move toward that base case to prevent infinite recursion.
Constructor Execution Order in main()
The deterministic sequence where constructors run in the exact order in which the objects are declared, causing the first declared object's constructor to execute first.