C- #define directive

#define directive

This is a preprocessor command which is used to replace any text within a C program with a more informative pseudonym.

For Example :-             #define  PI  3.14159

When the preprocessor is called it replaces each instance of the phrase PI with the correct replacement string which is then compiled. The advantage of using this is that if we wish to change the value of PI at any stage we need only change it in this one place rather than at each point the value is used.


Macros make use of the #define directive to replace a chunk of C code to perform the same task as a function but will execute much faster since the overhead of a function call will not be involved. However the actual code involved is replaced at each call to the macro so the program will be larger than with a function.


Macro to print an error message.

#define  ERROR printf( “\n Error \n” )

void main( )


if ( i > 1000 )

ERROR ;        /*  note must add ; in this case to make correct …C statement  */


error: Content is protected !!