Loading....
Coupon Accepted Successfully!

 

Define Preprocessor Directive

  • Preprocessors directives are lines included in the code of the program that are not program statement but directives for the preprocessor.
  • It is defined by using the symbol hash(#);
  • It is executed before the actual compilation of code beginning.
  • It is extended only across a single line of code.
  • No semicolon is used to terminate the process while using preprocessor.
  • No back slash is allowed in preprocessor.
  • To define a preprocessor, the general format is

# define identifier replacement

For example
# define pi 3.14
#define tsize 100

Program

#include<iostream.h>

#define getmax(a,b) ((a)>(b) ? (a) : (b))

int main()

{

int a=5, b;

b=getmax(a,2);

cout<<b<<endl;

cout<<getmax(7,a)<<endl;

return 0;

}

Note: Many things can be done during preprocessing phase include:
  • inclusion of other files through #include directive

  • definition of symbolic constants and macros through # define directive.





Test Your Skills Now!
Take a Quiz now
Reviewer Name