Difference between Preprocessor and Compiler

Question1: What is Difference between Preprocessor and Compiler?

Answer: Though, the preprocessor is the first to look at the source code file and performs several preprocessing operations before it’s compiled by the compiler. Nevertheless, compiler sets the source code file, say “hello.c”, through several phases of translation before jumps into preprocessing. Actually, it prepares the file for being preprocessed by preprocessor.

Firstly, it does mapping of characters in source code file to source character set. It takes care of multi-byte characters and trigraphs. Secondly, it locates character combinations of backslash ‘\’ followed by “newline character” and deletes them. For example, the two physical lines,

printf("hello \


printf("hello world\n");

Newline character is one you get by pressing Enter key and not the character representation ‘\n’ or symbolic constant \n.


This preparation is a useful feature as preprocessor expressions are required to be one logical line. Although, each logical line can be one or more physical lines.

Next, compiler breaks the text into a sequence of tokens and sequences of white space and comments. A token is a group of words separated by white spaces. Then replaces each comment by single white space. For example,

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
int/* declaring an integer variable */value;


int value;

After this, prepocessor processes source code. Because it processes the source code before it is compiled hence it’s called preprocessor. It starts it’s work by deleting the comments, following the #directives including header files on your request, replacing the replacement text for macros and symbolic constants, telling the compiler which block of code to accept or ignore. Preprocessor doesn’t know C. It simply takes text of one type and converts it to some other type.


Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.


Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.