STANDARD C PRE-PROCESSOR
What is Pre-Processor?
• Pre-processor is a program which performs before the
compilation.
source
file(.c) pre Pure linker/
HLL processor HLL compiler assembler
Object M/C loader EXE
code code FILE
• Pre-processor only notice # started statements.
• # is called as Pre-processor directive.
• The word after # is called as Pre-processor command.
Eg-#include , #define, #undef etc
This method is normally used to include standard library header files.
#include<header file> eg- #include<stdio.h>
Note- If header file is written inside < > compiler search in standard directory
#include “header file” eg- #include "cube.c"
Note- If header file is written inside " " compiler search in current directory
This method is normally used to include programmer-defined header files.
................................
................................
#include<stdio.h> add ................................
void main() ................................
{
printf("hello\n"); ................................
} void main()
qaz.c {
printf("hello\n");
}
qaz.i
Types of Pre-Processor directive
1. File Inclusion
2. Macros
3. Conditional Compilation
File Inclusion
This type of preprocessor directive tells the compiler to include a file in
the source code program. There are two types of files which can be
included by the user in the program.
Header File or Standard files: These files contains definition of pre-
defined functions like printf(), scanf() etc. These files must be included
for working with these functions. Different functions are declared in
different header files.
Syntax - #include<filename>
Eg- #include<stdio.h>
user defined files: When a program becomes very large, it is good
practice to divide it into smaller files and include whenever needed.
These types of files are user defined files.
Syntax- #include “ filename ”
Eg-#include “cube.c”
Macros-
The ‘#define’ directive is used to define a macro.
Syntax- #define symbolic constant value
Macros are a piece of code in a program which is given some
name.
Whenever this name is encountered by the compiler the
compiler replaces the name with the actual piece of code.
Note: There is no semi-colon(‘;’) at the end of macro definition.
Macro definitions do not need a semi-colon to end.
Eg- #include<stdio.h>
#define PI 3.14 macros
void main()
{
int radius,area;
printf(“enter radius to find area”);
scanf(“%d”,&radius);
area=PI*radius*radius;
printf(“area of circle is %d”,area);
}