Flashcard Deck · 20 cards · Public

CS106B - Programming Abstractions in C++

Master foundational C++ programming abstractions, including recursive backtracking, dynamic memory management, pointer arithmetic, and Big-O efficiency analysis. Ideal for students tackling rigorous computer science software engineering fundamentals.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
Pass-by-Value vs. Pass-by-Reference
Definition
In pass-by-value, a copy of the argument is passed to the function, so modifications do not affect the original variable. In pass-by-reference (using &), the function receives an alias to the original object, allowing direct modification and avoiding costly copying of large structures.
#2
Term
Base Case vs. Recursive Step
Definition
A recursive function requires two core components:
1. Base Case: The simplest scenario that returns a result directly without further recursive calls, preventing stack overflow.
2. Recursive Step: Reduces the problem into smaller subproblems and calls the function on those subproblems, progressing toward the base case.
#3
Term
Recursive Backtracking Pattern
Definition
A systematic technique for searching a decision space using recursion through three core steps:
1. Choose: Make a tentative decision.
2. Explore: Recursively solve remaining subproblems based on that choice.
3. Unchoose: Undo the choice (backtrack) to restore state before attempting alternative choices.
#4
Term
Stack vs. Heap Memory
Definition
  • Stack Memory: Automatically managed frame-by-frame during function execution. Extremely fast, but fixed in size and scope.
  • Heap Memory: Explicitly managed dynamic memory allocated by the programmer. Slower, but persists across function scopes until manually freed.
#5
Term
Dynamic Memory Allocation (new and delete)
Definition
Heap memory is allocated dynamically using new and must be freed manually using delete to prevent memory leaks:
c++3 lines
int* ptr = new int(42); // Allocates an int on heap
delete ptr;             // Frees allocated heap memory
ptr = nullptr;          // Prevents dangling pointer
#6
Term
Dynamic Memory for Arrays (new[] and delete[])
Definition
Dynamic arrays allocated on the heap using new[] must be deallocated using delete[] to ensure all elements are properly destroyed:
c++2 lines
int* arr = new int[100]; // Allocates array of 100 ints
delete[] arr;            // Correctly frees array memory
#7
Term
Dangling Pointer vs. Memory Leak
Definition
  • Dangling Pointer: A pointer referencing a memory location that has already been deallocated using delete. Accessing it results in undefined behavior.
  • Memory Leak: Dynamically allocated heap memory that is no longer accessible because all pointers referencing it were overwritten or lost without calling delete.
#8
Term
Pointer Arithmetic Mechanics
Definition
Adding an integer to a pointer p advances its address by bytes, where is the element type pointed to. For example, if p is an int* at address 0x1000, p + 1 points to 0x1004 (assuming 4-byte integers).
Showing 8 of 20 cards in this deck.
Study All Now

Related Flashcard Sets

Explore similar study materials created by the community

Browse community decks