










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Problem: What if we don’t know ahead of time (at compile time) the amount of variable space we will need? If we under estimate an array size, we’ll get a runtime error. If we over estimate an array size, we’ll have lots of unused memory. Solution: Allow variables to be created at execution time.
Dynamic Memory Defn: Dynamic memory is space that is allocated for variables at execution time. In C++, the operator new is used to create a variable dynamically. new does two things:
Example 1 : Dynamic Memory Allocation typedef int* int_ptr; int_ptr Count; Count = new int; If the heap looks like this:
Example 2 : Dynamic Memory Allocation typedef int* RecPointer; A. RecPointer P1, P2, P3;
C. P3 = P1;
D. P1 = new int;