&), the function receives an alias to the original object, allowing direct modification and avoiding costly copying of large structures.CS106B - Programming Abstractions in C++
Cards in this deck
(20 cards)Preview terms and definitions before starting your study session.
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.
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.
- 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.
new and delete)new and must be freed manually using delete to prevent memory leaks:int* ptr = new int(42); // Allocates an int on heap
delete ptr; // Frees allocated heap memory
ptr = nullptr; // Prevents dangling pointernew[] and delete[])new[] must be deallocated using delete[] to ensure all elements are properly destroyed:int* arr = new int[100]; // Allocates array of 100 ints
delete[] arr; // Correctly frees array memory- 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.
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).Related Flashcard Sets
Explore similar study materials created by the community
TypeScript - Advanced Type Systems, Generics & Design Patterns
Master advanced TypeScript features like generics, conditional types, and mapped types to build robust, scalable applications. This deck covers essential utility types, type narrowing techniques, discriminated unions, and the nuances between interfaces and type aliases, empowering you to write highly maintainable and type-safe code.
Harvard ECON1011 - Intermediate Microeconomics: Game Theory & Market Structures
Master key concepts in intermediate microeconomics with this comprehensive flashcard deck. Dive deep into game theory, market structures, strategic pricing, and general equilibrium models, perfect for Harvard ECON1011 students and anyone aiming to ace microeconomics.
MIT 18.03 - Differential Equations: Ordinary Differential Equations, Laplace & Fourier
Master MIT 18.03 Differential Equations with high-yield flashcards covering first and second-order ODEs, Laplace transforms, Fourier series, and matrix exponential state-space systems.
CPA Exam FAR - Financial Accounting & Reporting: US GAAP & Revenue Recognition
Master high-yield CPA FAR concepts covering ASC 606 revenue recognition, ASC 842 lease accounting, inventory valuation methods, and consolidated financial statements.