Preprocessor processes source program before it is passed to compiler.Preprocessor offers various preprocessor directives.They start with a # symbol.
Below are some of the preprocessor directives.
#include
This can include both the system and user header files in another file.
eg. #include<stdio.h>
eg. #define PI 3.1415
Wherever macro PI would be encountered in the program,this value would be substituted.
eg. #define AREA(r) PI * r * r
This paramaterized macro would take value of r and expand to it depending on the value.
Suppose the preprocessor encounters AREA(5) then 3.1415 * 5 * 5 would be
subsituted for it.
#undef
This undefines a macro.
eg. #undef PI
#ifdef
#ifdef MNAME
statements
#endif
Only if the macro MNAME is defined , the statements will be included in the output of the preprocessor.
Other directives include #ifndef,#pragma,#error,etc.
No comments:
Post a Comment