Typical C compilers produce an assembly that creates four "sections" of memory. The compiler / loader usually combines the various elements marked with the same section, together with loading the program into memory. The most common sections are:
"text": This is the actual program code. This is considered read-only (for example, the linker / loader on some machines may put it in ROM).
"data": This is just the allocated RAM area, with the original values โโcopied from the executable. The bootloader will allocate memory, then copy it to the original contents.
"bss": Same as data, but initialized with zeros.
"stack": just assigned by the loader for its program stack.
Global and static variables are placed in "data" and "bss" and, therefore, have a program life. However, static variables do not put their names in the symbol table, so they cannot be connected externally as global ones. The visibility and lifetime of variables are completely different concepts: the C syntax mixes the two.
"Automatic" variables are usually allocated on the stack during program execution (although if they are very large, they can be allocated instead of the heap). They exist only in the frame of the stack.
source share