Macro Taking Argument in C | Argumented Macro Preprocessor inC Programming

Pre-processor Macro taking Argument : Argumented Macro (Macro having Arguments)

  1. Everytime whenever the macro name is encountered , the arguments are replaced by the actual arguments from the program.
  2. Macroname having Arguments is called Argumented Macro.
  3. Argumented macro is as called as function macro as it looks like calling function.

Advantages of Argumented macro :

  1. Arguments are not Case sensitive .
  2. Numeric macro Executes faster than the function

Example of Macro Name:

#define SQU(x) (x*x)

Example :

#define SQU(x)(x*x)

int main()
int x;
float y;

x = SQU(3);
y = SQU(3.1);

printf("\nSquare of Integer : %d",x);
printf("\nSquare of Float : %f",y);


Output :

Square of Integer :  9
Square of Float   :  9.610000

Conclusion :

  1. We can pass any Numeric Parameter eg int,float,double
  2. So that Argumented macro is not case sensitive

Argumented Macro used for different purpose :

#define LARGE(x,y)((x)>(y)?(x):(y))
#define SQU(x)(x*x)
#define COM(s1,s2)(strcmp((s1),(s2))==0)