2. Definition
Preprocessors are some special
commands that start with hash (#)
symbol.
Preprocessing is done before
compilation and it generates expanded
source code.
Following diagram show the concept of
preprocessing:
5. #define
It can be used in 3 ways
1) It can be used to define constants.
2) It can be used to create shortcuts.
3) It can be used like a small function
(macro).
6. Example 1 – Defining Constants
#include<stdio.h>
# define N 10
void main()
{
int x;
x=N*5;
printf(“%d”, x);
}
8. Example 2 – Creating Shortcut
#include<stdio.h>
# define P printf(“Enter a number :”)
void main()
{
int x;
P;
scanf(“%d”, &x);
printf(“Value of x = %d”, x);
}
12. #include
This preprocessor is used to include header
files in our programs.
Header files contain functions and macros.
The code of header file is attached with our
program after preprocessing. So we can use
all the things defined in the header file in our
program.
E.g. printf() function is defined in a header
file called <stdio.h> . So we need to include
this header file to use printf() function in our
program.
13. #ifdef
This preprocessor is used for conditional
compilation.
Syntax
#ifdef MacroName
Statements
#else
Statements
#endif