List of Preprocessor Directives in C
The following table lists all the preprocessor directives available in the C programming language:
Preprocessor Directives |
Description |
---|---|
#define |
Used to define a macro. |
#undef |
Used to undefine a macro. |
#include |
Used to include a file in the source code program. |
#ifdef |
Used to include a section of code if a certain macro is defined by #define. |
#ifndef |
Used to include a section of code if a certain macro is not defined by #define. |
#if |
Check for the specified condition. |
#else |
Alternate code that executes when #if fails. |
#endif |
Used to mark the end of #if, #ifdef, and #ifndef. |
#error |
Used to generate a compilation error message. |
#line |
Used to modify line number and filename information. |
#pragma once |
To make sure the header is included only once. |
#pragma message |
Used for displaying a message during compilation. |
C Preprocessor Directives
In almost every C program we come across, we see a few lines at the top of the program preceded by a hash (#) sign. They are called preprocessor directives and are preprocessed by the preprocessor before actual compilation begins. The end of these lines is identified by the newline character ‘\n’, no semicolon ‘;’ is needed to terminate these lines. Preprocessor directives are mostly used in defining macros, evaluating conditional statements, source file inclusion, pragma directives, line control, error detection, etc.