After compilation of C++ creates four distinct regions of memory used for distinct functions:
STACK 3 |
HEAP 4 |
GLOBAL |
Program |
Variables |
Code |
2 |
1 |
The first area
(1) is used for storing the compiled code of the program. The second area
(2) is used for storing global variables of the program. It remains in memory till the program ends. The third region
(3) known as the stack is used for holding the return addresses of function calls, arguments passed to the function, etc. The last region heap is used for dynamic allocation.