+ 1

Why the answer is 3?

#define square(x)(x*x) int main() { int x, y=1; x=square(y+1); printf("%d",x); return 0; } O/P :- 3

27th Jul 2019, 6:12 AM
Suraj Patra
Suraj Patra - avatar
3 Réponses
+ 2
A macro definition will substitute the source code directly (the text itself). Therefore, the statement x = square(y + 1); is actually x = y + 1 * y + 1; so, x is y + y + y, and the result is 3
27th Jul 2019, 6:24 AM
Agent_I
Agent_I - avatar
+ 2
Thank you, swim and Agent_1 , I got it. Thanks for help.
27th Jul 2019, 6:31 AM
Suraj Patra
Suraj Patra - avatar