hi everybody,
wishing all people very best of life time...
what is differance between Stack and Heap memory with this concept used in C++
thanks
Printable View
hi everybody,
wishing all people very best of life time...
what is differance between Stack and Heap memory with this concept used in C++
thanks
Stack
When a function or a method calls another function which in turns calls another function etc., the execution of all those functions remains suspended until the very last function returns its value.
This chain of suspended function calls is the stack, because elements in the stack (function calls) depend on each other.
The stack is important to consider in exception handling and thread executions.
Heap
The heap is simply the memory used by programs to store variables.
Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.
When variables are created in a C++ program the memory required to hold the variable is allocated from the program stack,and when the variable goes out of scope, the memory which was taken on the stack is freed.
When memory is allocated dynamically (by the programmer) memory is taken from the heap .
In C++ memory is allocated dynamically using the new operator.