The difference between code area, constant area, static area, heap area, stack area

Code area: store the code of the program, that is, the machine instructions executed by the CPU, and it is read-only.

Constant area: store constants (amount that cannot be changed during the running of the program, for example: 10, string constant "abcde", array name, etc.)

Static area (global area): The storage area of ​​static variables and global variables is the same. Once the memory in the static area is allocated, the memory in the static area will not be released until the program ends.

Heap area: the programmer calls the malloc() function to actively apply, and the free() function is needed to release the memory. If the heap area memory is applied for and then forget to release the memory, it is easy to cause memory leaks

Stack area: store local variables, formal parameters and function return values ​​in the function. After the scope of the data in the stack area has passed, the system will reclaim the memory of the automatic management stack area (allocate memory, reclaim memory), without the need for developers to manually manage it. The stack area is like an inn. There are many rooms in it. After the guests come, the rooms are automatically allocated. The guests in the rooms can be changed, which is a dynamic data change.

Guess you like

Origin blog.csdn.net/weixin_46537765/article/details/104956618