Similar to Mac OS, Linux, and windows, different types of data are stored in different areas of the memory (segments, sections/segment ). You can specify various parameters when running the linker to control the program's memory organization. The following is a typical memory structure in windows.
(The figure is incorrect. Modify it later)
1) The operating system retains the location with the lowest memory address. Normally, applications cannot access the data of these addresses. One of the main reasons for the system to retain these spaces is to help check the reference of the NULL pointer. the pointer is usually initialized as null to indicate that the pointer is invalid.
2) stack space: a program is used to store local variables and other temporary data.
3) Heap Space: The program is used to maintain dynamic variables.
4) code segment: The machine instruction code used to save the program.
5) constant zone: stores the read-only data generated by the compiler.
6) read-only data segment: stores user-defined data, which can only be read and cannot be written.
7) Static zone: stores user-defined static variables that have been initialized.
8) Storage segment: Also known as BSS, stores user-defined uninitialized variables.
Generally, the compiler combines the code segment, constant area, and read-only data segment because the three segments contain read-only data.
Reference: volumn 1: Understanding the machine)