The memory used by C++ is divided into three parts: static memory, stack memory and heap memory
One, static memory
Static memory is used to store static variables and global variables in the program. This part of the memory is allocated at compile time and is not destroyed until the end of the program.
Second, the stack memory
The stack memory is used to store the non-static local variables defined in the function. This part of the memory is allocated when the function is called and destroyed when the function runs.
Three, heap memory
Heap memory is also called free space. Objects dynamically allocated when the program is running are stored in the heap, and its allocation and destruction need to be performed explicitly.