Home » Latest Articles

Execution process of a C/C++ program

Pre-processing, Compiling, Linking, Loading

Execution of a C/C++ program involves four stages using different compiling/execution tool, these tools are set of programs which help to complete the C/C++ program's execution process.

  1. Preprocessor
  2. Compiler
  3. Linker
  4. Loader

These tools make the program running.

1) Preprocessor

This is the first stage of any C/C++ program execution process; in this stage Preprocessor processes the program before compilation. Preprocessor include header files, expand the Macros.

2) Complier

This is the second stage of any C/C++ program execution process, in this stage generated output file after preprocessing ( with source code) will be passed to the compiler for compilation. Complier will compile the program, checks the errors and generates the object file (this object file contains assembly code).

3) Linker

This is the third stage of any C/C++ program execution process, in this stage Linker links the more than one object files or libraries and generates the executable file.

4) Loader

This is the fourth or final stage of any C/C++ program execution process, in this stage Loader loads the executable file into the main/primary memory. And program run.

Different files during the process of execution

Suppose, you save a C program with prg1.c – here .c is the extension of C code, prg1.c file contains the program (source code of a C program). Preprocessor reads the file and generates the prg1.i (prg1.ii – for c++ source code) file, this file contains the preprocessed code.
Compiler reads the prg1.i file and further converts into assembly code and generates prg1.s and then finally generates object code in prg1.o file.
Linker reads prg1.o file and links the other assembly/object code or library files and generates executable file named prg1.exe.
Loader loads the prg1.exe file into the main/primary memory and finally program run.
One more file is created that contains the source code named prg1.bak; it’s a backup file of the program files.

Execution of a C/C++ program


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.