Pre-processor Macro taking Argument : Argumented Macro (Macro having Arguments)
- Everytime whenever the macro name is encountered , the arguments are replaced by the actual arguments from the program.
- Macroname having Arguments is called Argumented Macro.
- Argumented macro is as called as function macro as it looks like calling function.
Advantages of Argumented macro :
- Arguments are not Case sensitive .
- Numeric macro Executes faster than the function
Example of Macro Name:
#define SQU(x) (x*x)
Example :
#include<stdio.h> #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); return(0); }
Output :
Square of Integer : 9 Square of Float : 9.610000
Conclusion :
- We can pass any Numeric Parameter eg int,float,double
- 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)