History of C
History of C
Preprocessor Directories
Pre-Processor Directives
• List of pre-processor directives :
• #include
• #define
• #undef
• #ifdef
• #ifndef
• #if
• #else
• #elif
• #endif
• #error
• #pragma
1. #include
• The #include pre-processor directive is used to paste code of given file into current file. It is used include
system-defined and user-defined header files. If included file is not found, compiler renders error. It has
three variants:
• #include <file>
• This variant is used for system header files. It searches for a file named file in a list of directories specified by
you, then in a standard list of system directories.
• #include "file"
• This variant is used for header files of your own program. It searches for a file named file first in the current
directory, then in the same directories used for system header files. The current directory is the directory of
the current input file.
• Object-like Macros
• Function-like Macros
Object-like Macros
The object-like macro is an identifier that is #include <stdio.h>
replaced by value. It is widely used to represent #define PI 3.1415
numeric constants. For example:
main()
#define PI 3.1415
{
Here, PI is the macro name which will be
replaced by the value 3.14. Let’s see an example printf("%f",PI);
of Object-like Macros : }
Output: 3.14000
2. Function-like Macros
The function-like macro looks like #include <stdio.h>
function call. For example:
#define MIN(a,b) ((a)<(b)?(a):(b))
void main() {
#define MIN(a,b) ((a)<(b)?(a):(b))
printf("Minimum between 10 and 20 is: %d\n", MIN(10,20));
Here, MIN is the macro name.
Let’s see an example of Function- }
like Macros :
Output: