Preprocessor Directives
In this tutorial we are going to learn Preprocessor directives in c.
Preprocessor directives are the statements which tells the compiler to change the program floor to include library in file (or to import external files).
Preprocessor directives are the first statement of the program.
Preprocessor directives are start with the # symbol and it does not contain semicolon at the end.
There are some preprocessor directives in c which are as follows
#include
#error
#define
#if
Etc
Include directives :-
- Include directives is inclusion directives
- Include directives is used to include or import the file to program.
Syntax :-
#include<file_name>
Or
#include”file_name”
In above syntax, we first write # symbol , include keyword and file name in between < and > operator or in between double quotes.
Example :-
#include<stdio.h>
In above example, this statement tells compiler to include stdio.h library file to the program.
Program to illustrate include preprocessor directives in c
1234567891011121314151617 | #include<stdio.h> // include preprocessor directives#include<conio.h> //void main (){clrscr ();. //Included in conio.h fileprintf(“\n Preprocessor directives in c”);printf(“\n standard input output file included:”);getch();} |
Output:-
Preprocessor directives in c
Standard input output file included
#define or macro directives :-
This directives is called as definition directives.
These directives used to define symbolic constant or macros.
Macro is a expression or statement which are expanded in program when to called.
Syntax :-
#define NAME VALUE
Or
# define #EXP(A) expansion_in_A
In above syntax, every occurrences of NAME and EXP(A) is replaced by appropriate statement or expression in preprocessor.
Program to illustrate #define preprocesor directives in c
12345678910111213141516171819 | #include<stdio.h>#define F(X) X*Xvoid main(){int x,y;printf(“Enter The Value Of ‘X’ : “);scanf(“%d”,&x);y=F(X);printf(“\nSolution : %d”,y);} |
Output:-
Enter The Value Of ‘X’ :
4
Solution : 16