+ 2
Why the Output is 16?
I thought the output will be 1, But i've got 16. #define sqr(x) x*x int x = 16/sqr(4); printf("%d", x); Why...?
3 Answers
+ 3
#define macros aren't functions even if they look so. They actually just kind of copy and paste code. In your case the macro is preprocessed to:
int x = 16/4*4;
That's 16. If you want to avoid this you have to use parenthesis around your macro like this:
#define sqrt(x) (x*x)
+ 3
Mirielle and Aaron Eberhardt Thank you guys