C++ Memory Management
We know that arrays store contiguous and the same type of memory blocks, so memory is allocated to the array at the time of declaration. If we declare an array of size n, we can’t extend its size more than that during the runtime. If we declare an array of the maximum size, most of the memory can be wasted.
C++ Memory Management allows us to allocate memory in run time and this feature is known as dynamic memory allocation. Unlike other languages like python, Java, etc C++ doesn’t take care of unused memory. Thus, we need to dynamically deallocate the memory manually after the completion of the lifetime of variables.
Allocation and Deallocation of memory are done using new and delete operators.
A new operator is used to create a block of memory on the heap.