Stack allocation is a work of compiler. All stack variables are automatic. When variable is out of scope, compilere deletes stack objects automatically. The stack is memory area that temporarily holds the arguments to the function as well as any variables that are defined local to the function.
The heap is a separate area from the program and the stack.You use new ( malloc in C) and delete(free in C) to allocate and deallocate objects in heap memory. The advantage if using new and delete is they provide an efficient wat to allocate and deallocate memory.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.