Types of Preprocessor Directives in C
The Preprocessor is a program that is executed before the compilation of a source program written by the user. A source program is processed using commands. The Preprocessor Directives begin with a hash (#) followed by the command.
#include // It is a directive to include a file
Remember that the program written by the user is called a source program which is translated into a machine language program by the compiler and is called an object program. In the actual compilation process in C language, the preprocessor processes the source program and the direction for the compilation of a program is passed.
Types of Preprocessor Directives:
There are three types of Preprocessor Directives in the C language:
1. Macro Substitution: Constant values or expressions can be identified using symbolic names. At the time of preprocessing, all these symbolic names are replaced by values/expressions. This process is referred to as Macro Substitution. It has the following syntax:
#define identifier value or string
2. File Inclusion: A file inclusion directive is commonly used to include the contents of standard header files in a C Program. Any previously written program can be included in a new program. It enables the user to use the functions and macros defined in that program. Even bigger programs stored in different files can be included in a new program as a header file. It has the following syntax:
3. Conditional Compilation: It can be used to include a file or macro depending on some conditions. It is useful to define parameters based on different platforms/hardware used in a computer. It has the following syntax:
#ifdef SAMPLE <statement block-1> else <statement block-2> #endif