#include <stdio.h>
#define SQRT(X)X*X
int main(){
int x=16/SQRT(4);
printf("%d",x);
return 0;
}
this output is 16 why? firstly i defined macro and then try do calculation
#include <stdio.h>
#define SQRT(X)X*X
int main(){
int x=16/SQRT(4);
printf("%d",x);
return 0;
}
this output is 16 why? firstly i defined macro and then try do calculation
Currently int x=16/SQRT(4);
will expand to int x=16/4*4;
which is clearly 16. Use brackets to ensure the macro expansion is as intended:
#define SQRT(X) ((X)*(X))
Aside: SQRT
is an odd name for the macro as that usually means "square root". SQR
or SQUARE
would be a more appropriate name.