Search⌘ K

Pointers and Dynamic Memory

Explore how pointers enable dynamic memory management in C++ by accessing heap memory. Learn to allocate and release memory using new and delete, understand pointer declarations, and manage dynamic objects efficiently to write flexible and reusable code.

Heap: The Dynamic Memory Store

The dynamic section of memory known is called heap. This is a vast space of memory which is not being managed by the CPU.

We can specify the amount of space we want, and a random portion of the heap will be reserved for us. While the heap does allow us to use as much space as we want, the look-up operation is slower compared to a stack. However, a variable in dynamic memory (heap) can have a “global” scope instead of just being a local variable ...