Only the memory allocated in runtime occupied the heap area? Or the stack is also the part of heap memory. I bit confused where is actually the stack and heap memory present in storage device?
Data storage at heap
Hey @Vikaspal
Stack and heap memory are both different. While you can dynamically declare objects in let’s say a recursive function ( stack dynamic allocation ) or with keyword new ( heap allocation ), the crucial difference arises from persistence of value. A variable declared in stack memory will be automatically released by system when stack is popped off. If you try to access the variable again you’ll get garbage value. However, a value declared using new ( heap ) persists as long as it is not deleted using delete keyword.
If your doubt is resolved please mark this as closed.
okay got it. We can says that they are two methods of memory allocation
Right. If your doubt is resolved please mark it as closed.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.