Science, asked by arnab895, 1 year ago

What are the dynamic memory allocation and de-allocation operators in c++? explain?

Answers

Answered by Romanreings11
0
There are two ways that memory gets allocated for data storage:Compile Time (or static) AllocationMemory for named variables is allocated by the compilerExact size and type of storage must be known at compile timeFor standard array declarations, this is why the size has to be constantDynamic Memory AllocationMemory allocated "on the fly" during run timedynamically allocated space usually placed in a program segment known as the heap or the free storeExact amount of space or number of items does not have to be known by the compiler in advance.For dynamic memory allocation, pointers are crucial

Dynamic Memory Allocation

We can dynamically allocate storage space while the program is running, but we cannot create new variable names "on the fly"For this reason, dynamic allocation requires two steps:Creating the dynamic space.Storing its address in a pointer (so that the space can be accesed)To dynamically allocate memory in C++, we use the new operator.De-allocation:Deallocation is the "clean-up" of space being used for variables or other data storageCompile time variables are automatically deallocated based on their known extent (this is the same as scope for "automatic" variables)It is the programmer's job to deallocate dynamically created spaceTo de-allocate dynamic memory, we use the delete operator
Similar questions