Stage 3 · Lesson 7 of 9
Memory: the stack and the heap
A running program uses two main areas of memory. The holds a frame for each call in progress, with that call's . It grows when you call a function and shrinks when the function returns.
That makes it fast and automatic, but small, so very deep overflows it. The heap holds data whose size or lifetime is not tied to one call, such as lists, objects and long strings. You reach it through references or pointers (stored addresses).
In C++ you control how long heap data lives, ideally through std::vector and smart pointers. Python, Java, JavaScript and C# use instead: the runtime frees unused heap objects for you. Many "why did this change?" bugs come from two references to one heap object.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
Weeks 0, 1, 2 and 4 teach C, arrays and memory; the difficulty is the point
- VideoFreeCrash Course Computer Science
CrashCourse · Beginner
Short free videos from logic gates to operating systems; episodes 1 to 20
Keep handy
Also worth your time
- What Happens WhenGo deeper
Everything from a key press to a rendered page; read it after this stage