Sunday, December 23, 2012

Preprocessor

Before compiling a C file, a process called preprocessing is done on the source code by a program called preprocessor. 

Consider the C code below:

#include <stdio.h>
void main()
{
    printf("Hello World");
}

In the above program the program starts with the line #include <stdio.h>. This line is a preprocessor directive. The preprocessor processes the program before the compiler. All lines beginning with # symbol will be processed by the preprocessor. The #include directive causes the preprocessor to effectively insert the stdio.h file into the C program. When the compiler compiles the program it will see the contents of the stdio.h file instead of the preprocessor directive.

Note: The stdio.h file does not contain the actual statement of the printf function. It only has the information that the function printf exists and can accept a character string.

No comments:

Post a Comment