Preprocessor
A preprocessor is a program which will executed automatically before passing the source program to compiler means it takes the source c program as an input before compilation and reads all preprocessor statements begin with #(hash) symbol and processes those statements which may result in the alteration of the 'C' code and generates a complete 'C' file and gives it to the compiler as an input.All preprocessor directives should be not ended with (;).
Preprocessor statements are also called the preprocessor directive.We can place pre-processor directives anywhere in the program, but generally recommended to place top of the program before defining the first function.
Header Files
#include<stdio.h>#include<conio.h>
Symbolic Constants
#define PI 3.14159
#define TRUE 1
#define FALSE 0
In ‘C’ language pre-processor directives are classified into 4 types
- Macro substitution directives. example: #define
- File inclusion directives. example: #include
- Conditional compilation directive. example: #if, #else, #ifdef, #undef
- Miscellaneous directive. example: #error, #line
#if, #elif, #else, #endif
These preprocessing directives create conditional compiling parameters that control the compiling of the source code. They must begin on a separate line.
Syntax:
#if
constant_expression#else
constant_expression
#endif
or
#if#elif
constant_expression#endif
The compiler only compiles the code after the
#if
expression if the constant_expression evaluates to a non-zero value (true). If the value is 0 (false), then the compiler skips the lines until the next #else
, #elif
, or#endif
. If there is a matching #else
, and the constant_expression evaluated to 0 (false), then the lines between the #else
and the #endif
are compiled. If there is a matching #elif
, and the preceding #if
evaluated to false, then the constant_expression after that is evaluated and the code between the #elif
and the #endif
is compiled only if this expression evaluates to a non-zero value (true).
No comments:
Post a Comment