How C Processor Works | Processing of Preprocessor Directives with Flowchart



We all know that preprocessor comes before compiler so complete source code will be first processed by the preprocessor and then output will be given to the compiler.

How C Processor Works | Processing of Preprocessor Directives with Flowchart

following flowchart clearly explains the working of Pre-processor Directive –

Explanation of Working :

Step 1 : Writing C Program

Suppose we have written above C Program.Let us say name of program be hello.c . Now we are going to feed this source code to preprocessor before compiling.

#include<stdio.h>
#include<conio.h>
#define MAX 10

void main()
{
int i = MAX;

printf("Age of Child : %d",MAX);

getch();
}

Step 2 : Is there any C Preprocessor Directive ?

Now second steps is to check whether there is any preprocessor directive written inside the c program that can be processed by preprocessor.Meaning of preprocessor is to process it before.

  1. Preprocessor directives are processed before giving source code to Compiler.
  2. First Preprocessor will check whether given source code contain any pre-processor directive or not.
  3. If there is any preprocessor written in code then preprocessor will perform some tasks which makes original source code compiler readable

Final Source Code after Processing by Preprocessor :

void main()
{
int i = 10;
printf("Age of Child : %d",10);
getch();
}

We can see all header files are removed.New lines are replaced by spaces and all large spaces are replaced by single space.

Step 3 : Compiler Phase

Compiler will compile program , creates object code which can further read by computer. [ Read : What is Compiler ? ]

Recommended Reading : Phases of Compiler –

Lexical Analyzer | Syntax Analyzer |  Semantic Analyzer

Conclusion : Preprocessor Directives

  1. Preprocessor Processes Source Code before giving it to compiler.
  2. It is Compiler Independent.