Join Regular Classroom : Visit ClassroomTech

Compilation of c program

The computer doesn’t understand the code we write, it needs to be converted into machine language with the use of a compiler. The compilation is a method whereby the source code is converted into object code.


There are 4 phases through which a compilation process is done-

1. Preprocessor
The source code with extension “.c” is first passed through a preprocessor which expands the code and removes all the comments.
2. Compiler
The expanded code then passed to a compiler, and the compiler converts the expanded code to assembly code and passes it to the assembler.
3. Assembler
Assembler collects the assembly code and converts it into an object file, with the “.obj” extension. The file name is the same as the source file, therefore if the source file name is “file. c”, then the object file name would be “file. obj”.
4. Linker
The object file then comes to the linker. The main work of the linker is to link the object code of our program to the object code of the library file and other files. We use many library functions in our c program. These library functions are pre-compiled, and the object code of these library functions is saved with the “.lib” extension. The linker gives an executable file after linking. This executable file has an extension “.exe”, and the name is the same as the source file. If the source file name is “file. c”, then the executable file name would be “file.exe”.

Recent Posts