Whenever a C program file is compiled and executed, the compiler generates some files with the same name as that of the C program file but with different extensions. So, what are these files and how are they created?
Below image shows the compilation process with the files created at each step of the compilation process:
Every file that contains a C program must be saved with ‘.c’ extension. This is necessary for the compiler to understand that this is a C program file. Suppose a program file is named, first.c. The file first.c is called the source file which keeps the code of the program. Now, when we compile the file, the C compiler looks for errors. If the C compiler reports no error, then it stores the file as a .obj file of the same name, called the object file. So, here it will create the first.obj. This .obj file is not executable. The process is continued by the Linker which finally gives a .exe file which is executable.
Linker: First of all, let us know that library functions are not a part of any C program but of the C software. Thus, the compiler doesn’t know the operation of any function, whether it be printf or scanf. The definitions of these functions are stored in their respective library which the compiler should be able to link. This is what the Linker does. So, when we write #include, it includes stdio.h library which gives access to Standard Input and Output. The linker links the object files to the library functions and the program becomes a .exe file. Here, first.exe will be created which is in an executable format.
Loader: Whenever we give the command to execute a particular program, the loader comes into work. The loader will load the .exe file in RAM and inform the CPU with the starting point of the address where this program is loaded.
Instruction Register: It holds the current instructions to be executed by the CPU.
Program Counter: It contains the address of the next instructions to be executed by the CPU.
Accumulator: It stores the information related to calculations.
The loader informs Program Counter about the first instruction and initiates the execution. Then onwards, Program Counter handles the task.
Difference between Linker and Loader
|Linker generates the executable module of a source program.||Loader loads the executable module to the main memory for execution.|
|Linker takes the object code generated by an assembler, as input.||Loader takes executable module generated by a linker as input.|
|Linker combines all the object modules of a source code to generate an executable module.||Loader allocates the addresses to an executable module in main memory for execution.|
|The types of Linker are Linkage Editor, Dynamic linker.||The types of Loader are Absolute loading, Relocatable loading and Dynamic Run-time loading.|
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Write a C program that does not terminate when Ctrl+C is pressed
- C program that does not suspend when Ctrl+Z is pressed
- Does C support function overloading?
- How does "void *" differ in C and C++?
- Does C++ compiler create default constructor when we write our own?
- How does free() know the size of memory to be deallocated?
- When does compiler create default and copy constructors in C++?
- Does overloading work with Inheritance?
- How does Duff's Device work?
- Why variable name does not start with numbers in C ?
- Why does sizeof(x++) not increment x in C?
- How Does the Blockchain Work?
- What does main() return in C and C++?
- How does Volatile qualifier of C works in Computing System
- C program to detect tokens in a C program
- C program to print a string without any quote (singe or double) in the program
- C Program for Program to find area of a circle
- C Program for Program for array rotation
- Lex Program to remove comments from C program
- Hello World Program : First program while learning Programming
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : RishabhPrabhu