Allocation of Dynamic Memory
Learn how memory can be dynamically allocated to variables in C++.
We'll cover the following
Introduction
For dynamic allocation, we have to do the following two steps:
- First, allocate the dynamic space.
- Then, store the starting address of the dynamic space in the pointer.
new
operator:
The unary operator new allocates memory in bytes during the run time from the free store.
If memory is available on the free store, the new operator will reserve that memory and return its starting address.
Syntax
The basic syntax for getting memory during the run-time is given below:
Get hands-on with 1400+ tech skills courses.