The following Figure summarizes the steps involved in the process of building the C program starting from the compilation until the loading of the executable image into the memory for running the program.
A typical compile, link and execute stages for the running program
The Process (image)
The diagram below shows the memory layout of a typical C’s process (Linux/Unix). The process load segments (corresponding to "text" and "data" in the diagram) at the process's base address. The main stack is located just below and grows downwards. Any additional threads or function calls that are created will have their own stacks, located below the main stack. Each of the stack frames is separated by a guard page to detect stack overflows among stacks frame. The heap is located above the process and grows upwards.
In the middle of the process's address space, there is a region is reserved for shared objects. When a new process is created, the process manager first maps the two segments from the executable into memory. It then decodes the program's ELF header. If the program header indicates that the executable was linked against a shared library, the process manager will extract the name of the dynamic interpreter from the program header. The dynamic interpreter points to a shared library that contains the runtime linker code. The process manager will load this shared library in memory and will then pass control to the runtime linker code in this library.
A typical C’s process memory layout on an x86.