Prashant | Wed, 10 Jun, 2020 | 155
In this tutorial we will learn about macros and prepocessors, and you will also learn about how to use and #inlcude #define and conditional compilations.
The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled. These transformations can be the inclusion of header file, macro expansions etc.
All preprocessing directives begin with a
# symbol. For example,
#define PI 3.14 #include <stdio.h>
All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −
|Sr.No||Directives & Descriptions|
Substitutes a preprocessor macro.
Inserts a particular header from another file.
Undefines a preprocessor macro.
Returns true if this macro is defined.
Returns true if this macro is not defined.
Tests if a compile time condition is true.
The alternative for #if.
#else and #if in one statement.
Ends preprocessor conditional.
Prints error message on stderr.
Issues special commands to the compiler, using a standardized method.
ANSI C defines a number of macros. Although each one is available for use in programming, the predefined macros should not be directly modified.
|Sr.No||Macro & Descriptions|
The current date as a character literal in "MMM DD YYYY" format.
The current time as a character literal in "HH:MM:SS" format.
This contains the current filename as a string literal.
This contains the current line number as a decimal constant.
Defined as 1 when the compiler complies with the ANSI standard.
8. Tokens In C
11. Variables In C
15. Constant In C