Process of C Program Compilation
Compilation process means Changing C program written by humans into a program that computer can understand and run.
Computer cannot understand C language directly.
So, it converts step by step
Example C Program
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}File name: program.c
Step-by-Step Compilation (Simple)
1. Preprocessing (Cleaning Step)
What it does:
- Removes comments
- Adds header files
- Replaces
#define
In our example:
#include <stdio.h>Computer adds full code of stdio.h here.
Output (internally):
program.iThink like:
Teacher gives you full question paper before exam.
2. Compilation (Checking & Translating)
What it does:
- Checks grammar (syntax)
- Converts C code into assembly language
Error example:
printf("Hello World")(missing ;)
Compiler gives error
Output:
program.sThink like:
Teacher checks your answers for mistakes.
3. Assembly (Machine Code Making)
What it does:
- Converts assembly code into machine code (0 & 1)
Output:
program.oThink like:
Translator converts English to computer language.
4. Linking (Final Joining)
What it does:
- Joins:
- Your code
- Library code (like
printf)
- Makes final runnable file
Output:
a.out (Linux / Mac)
program.exe (Windows)Think like:
Final book binding before printing.
Full Flow (Easy Line)
program.c → Preprocessing → Compilation → Assembly → Linking → Executable fileOne-Line Answer
The compilation process converts a C program into an executable file usingpreprocessing,compilation,assembly, andlinking.
