Pre Processor Directives

Preprocessor directives are usually starts with #. Say for example #define ABC text. Here, #define is the preprocessor directive. As the term says the compiler pre-process the source code file before the actual compilation. It the preparation goes with some set action and some of which are specified to the compiler through preprocessor directives.

In the above example before compiling the file it will look for all the pre-processing directive and takes necessary action. In our example it will look for the ABC and replaces that ABC with the token text. There are more such pre-processor directive exists. Always remember that preprocessor directive telling the compiler to do some preparation on the source before generation the object and assembly code based on the source code.

Let us consider one more statement #include <conio.h>, which is presented, in the first line of the cpp file say for now MyFile.cpp. Also consider that you made a call to the function getch() in the file somewhere after the #include. And, you do not implement the function.

Now, when you compile the file you get object form of the file MyFile. Even though you do dot defined the function the compiler identifies it. Because the pre-processing that is done before the compilation replaces the #include <conio.h> with the entire content of the conio.h. And conio header file provides all the detailed required for the getch function. One more point to mention is that this is why we always place the header file at the top of our source files c or cpp. The #included file content placement provides all the definition like function or variable whatever it is before they are actually going to be used later in the same file. And we call this pre-processing because the compilation goes successful after the pre-processing preparation of the code file content.