Preprocessors are the Source of our Program those are Executed whey they are passing to Compiler and Preprocessors are always executed at the Time of Compilations. Preprocessors provide many features called Preprocessor directives and Each Preprocessor is declared with # symbol and This Directive must be written before a main program.
Programs starts with code line #include <stdio.h>. Here, the directive #include is a preprocessor command. All preprocessor commands start with the sign#. The command given above directs the compiler to include the header file <stdio.h> (standard input/output header file) from C Standard Library in this program. Standard input is used to denote input from keyboard and standard output is used to indicate display on the monitor connected to the computer. A program that requires standard input and standard output must include the header file <stdio.h> as it has been done in Program. The header file <stdio. h> also contains many other functions that help in formatting the input/output of a program as well.
More than one header file from C Standard Library may be included in a program if these are required for the manipulation of data of the program. For example, if you want to carry out evaluation of mathematical functions such as square-root, sine or cosine of angles, log(x), or evaluation of exponential functions, you must include the header file <math.h>.This header file has the procedural software for evaluations of many such functions. For including more than one header files in a program, these should be written in successive lines. Only one header file is written in one line. The name of each header file, if it belongs to the C Standard Library, is enclosed between the angular brackets < >. The names end with extension (.h) as illustrated below.
#include <stdio.h>
#include <math.h>
The Preprocessor’s are Used For Two Purposes either they are used as Macros and either they are used as File inclusions like Many Times we write #include this is also a Preprocessor directive which is used for Including the Contents of a File Like iostream.h and either conio.h or any other File But the Macros are Also Called as Small Programs or The Macros are Used for Giving a Short names to Long Statements and Long Keywords and a user can Specify his own names to a keyword of c language
Macros are always define by using a #define Statement and For Defining our Own Macro First we have to specify our name for a Macro then we writes the Statements those are to be Executed When a Macro is Called or When that Name is used in any where in a program For Defining a Macro We have to Write Like This
#define Integer int
Now we can use Integer instead of int .But Always Remember we are not Replacing a Word with our Words We are just Giving a another name to a built in Keyword
In Macro we can also write any Statements and any Expression for Example
#define Max 100
#define or ||
#define Sqr(x) x*x
These are the Some Examples of Writing a Macro in the First Macro we defines a Max Word Wherever we use Max then Compiler will treat as 100 and Second Macro is or name to a or Symbol means Now Whether We can use a or Symbol and Instead of Putting a Symbol we can and either write a or word. Third Macro defines a Sqr(x) Whenever we writes Sqr with a Number then this will gives us a Square of a number etc.
There are many Conditional Compilation Macros those are used for Performing operations on Macros Like Checking the Value of Macro and To Check Whether a Macro is Defined or not
The Various Condition Compilation Macros are as follows:-
1. #ifdef:- This is used for Checking either a Macro with a Specified Name is Defined or not .Or it checks Whether a Macro is defined For use.
2. #undef:- This is Used for Un-defining a Macro. Or if we want to remove the definition of a Macro from our Program .then we can use #undef.
3. #ifndef:- This Condition Compilation is used for Check either a Macro is not Defined if a Macro really not defined then this will gives us true or if a Macro is defined then this will gives us false
4. #if :- #if condition Compilation Macro if used for Checking a value of Macro that is defined in a Macro definition or it checks whether an Expression evaluates to nonzero or not and always Remember Every #if Macro is must be Closed with the help of #endif
5. #else:- Used the Condition of First #if Macro is False . This is Similar to simple If else but Difference is that if –Else operates on value of Variable but #if performs or it either checks the Value of a Macro and this will be Executed When no Match of Macro Value is to be found same as else statement
6. #else if:– This Directive is used when we wants to Check one more Condition upon the Macros When #if is False then the Compiler will check another value that is defined in #else if Directive and also Every #elseif directive must be end with #endif