A preprocessor is a program that sends source code before it passes through the compiler. It operates according to preprocessing directives starting with the # symbol.
There are three types of preprocessor commands, as follows:
Macro replacement directives.
File contains directives.
Compiler control directives.
It replaces each occurrence of an identifier with a predefined string.
The syntax for defining a macro replacement directive is as follows:
# define identifier string
For example,
#define PI 3.1415 #define f(x) x *x #undef PI
The following is a C program for a macro replacement directive−
#define wait getch( ) main ( ){ clrscr ( ); printf ("Hello"); wait ; }
When the above program is executed, it produces the following results−
Hello
You can use the #include directive to include external files that contain function (or) macro definitions.
The syntax of the file inclusion directive is as follows:
# include <filename> (or) #include "filename"
The following is a C program for the file inclusion directive:
Real-time demonstration
#include <stdio.h> main ( ){ printf ("hello"); }
When the above program is executed, it produces the following results −
Hello
The function printf() is defined in the
The C preprocessor provides a feature called conditional compilation, which can be used to turn on (or off) a specific line (or group of lines) in a program ).
The following is a C program of compiler control instructions:
Real-time demonstration
#if, #else, #endif etc. #define LINE 1 #include<stdio.h> main ( ){ #ifdef LINE printf ("this is line number one"); #else printf("This is line number two"); #endif }
When the above program is executed , it produces the following result −
This line number one
The above is the detailed content of What are preprocessor commands in C language?. For more information, please follow other related articles on the PHP Chinese website!