0
Give explanation to this question
#define square(x) x*x Printf("%d",square(4+1));
3 Answers
+ 6
Notice that wrapping parenthesis may eliminate the problem but it wouldn't be a remedy for undefined behavior caused by increment/decrement operator like so
int a = 4;
printf("%d", square(++a)); // UB
_____
https://en.wikipedia.org/wiki/Undefined_behavior#Examples_in_C_and_C++
+ 2
You're defining a macro/preprocessor directive that will replace every occurrence of "square(x)" in the source code with "x*x" before the code is compiled.
Unfortunately, this will lead to wrong/unexpected results because it will replace "square(4+1)" with "4+1*4+1", which is 9, instead of 25.
To avoid that, you can use #define square(x) (x)*(x) instead: square(4+1) => (4+1)*(4+1) = 25.
0
Answer 25 or 9