Preprocessor directives in C: #define, function like macro, #error, #include

#define: #define directive is an identifier and a macro. A set of character sequences are replaced for the identifier when it is encountered in source file. The replacement of these set of characters are known as macro replacements. The macros are usually declared in uppercase characters.


#define macro_name character_sequence

For Example:

#define MAX_SIZE 250

Function like macro: Function like macro is a process in which whenever the macro name is encountered, the arguments used in its definition are replaced by the actual arguments found in the program. It is used for increasing the execution speed

#error: #error directive is used to stop compilation of a program.


#error error_message

#include: #include directive is used to inform the compiler to read a source file. It is used basically to include library functions.

It can be declared in two ways:

1) Using quotes. In this process file is searched in an implementation defined way. For Example: #include “stdio.h”

2) Using angle brackets. In this process file is searched as defined by the maker of the compiler. For Example: #include <stdio.h>

Leave a Reply