preprocessor directives in c

Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.


Commands used in preprocessor are called preprocessor directives and they begin with ”#” symbol. Below is the list of preprocessor directives that C language offers.

1 Macro
syntax:
#define 
This macro defines constant value and can be any of the basic data types.

2 Header file inclusion 
syntax:
#include <file_name>
The source code of the file ”file_name” is included in the main program at the specified place

3 Conditional compilation
syntax:
#ifdef, #endif, #if, #else, #ifndef
Set of commands are included or excluded in source program before compilation with respect to the condition

4 Other directives 
syntax:
#undef, #pragma
#undef is used to undefine a defined macro variable.
#Pragma is used to call a function before and after main function in a C program

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s