C Programming and Data Structures: Unit II: C Programming – Advanced Features

Preprocessor Directives

Definition, Syntax, Example C programs

• Pre-processing is a separate step applied on the source file before presenting it to compilation process.

Preprocessor Directives

• Pre-processing is a separate step applied on the source file before presenting it to compilation process.

• The C- preprocessor is a text substitution toll. It instructs the compiler to do all the necessary preprocessing before and after the compilation

• The pre-processor directive is written at the beginning of the program with the # preceded to it.

• Following is a list of important Preprocessor directives -


• Pre-processor Examples

(1) #define SIZE 10

This directive tells the compiler to replace the instance of SIZE with 10.

 (2) #include<stdio.>

This directive tells to get stdio.h from system libraries and add the text to the current source file.

(3) #include "myfile.h"

This line tells the compiler to get myfile.h from local director and add the contents with the current source file.

(4)

#undef F_SIZE

#define F_SIZE 80

It tells to undefine existing F_SIZE and define it as 80.

(5)

 #ifndef MSG

#define MSG "Welcome" a

#endif

It tells to define MSG only if MSG isn't already defined.

 

C Programming and Data Structures: Unit II: C Programming – Advanced Features : Tag: : Definition, Syntax, Example C programs - Preprocessor Directives