Site icon TestingDocs.com

C Preprocessor Directives

Overview

C Preprocessor directives instruct the preprocessor to modify the C program before the compilation process. A preprocessor is a program that modifies the C program before compilation. The preprocessor directive statements begin with the #.

Examples

Some of the examples of the C Preprocessor Directives are as follows:

#include

To use a C standard library, we must include the library header file in the code using the #include directive.  For example, to include the stdio.h header file, we can use the following  #include directive statement.

#include <stdio.h>

#define

The #define directive is used to instruct the preprocessor to replace the occurrences of the textual constant with the defined value. We can use this directive to define constants in the C program.

For example, to define the PI value we can use the following #define statement.

#define PI 3.14

 

Common Mistakes

To use the standard input and output library function in the C program we have to include the stdio.h header file. To avoid compilation warning messages like the one shown:

Unlike the programming statements, there is no need to terminate the preprocessor directive by a semicolon.

Example:

#include <stdio.h>;

If you terminate a preprocessor directive with a semicolon compiler will throw a warning message. Sample warning message

warning: extra tokens at end of #include directive #include <stdio.h>;

To resolve the warning message, remove the semicolon in the preprocessor directive.

Exit mobile version