+ 2

Can anyone explain this ?

#define square (x)(x*x) int main() { x = square (y+1); printf("%d\n",x); return 0 ; }

20th Jul 2020, 7:02 AM
Ellapu Keerthi
Ellapu Keerthi - avatar
5 Answers
+ 6
It will be calculate like this if y =1; x=square (1+1) square (x) x*x which means 1+1*1+1 so answer will be 3 If it will be x=square (2+4) Then it will be 2+4*2+3 hope u understood
20th Jul 2020, 6:19 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Yes the value of y is 1
20th Jul 2020, 7:38 AM
Ellapu Keerthi
Ellapu Keerthi - avatar
+ 2
Thank you . I got it .
20th Jul 2020, 7:39 AM
Ellapu Keerthi
Ellapu Keerthi - avatar
+ 1
The answer is 3 but how ?
20th Jul 2020, 7:02 AM
Ellapu Keerthi
Ellapu Keerthi - avatar
+ 1
square(y+1) is replaced at compile time by : (y+1*y+1) I think y is 1 in your code (you didn't show it here, so I don't know the value of y). So : 1 + 1*1 + 1 = 3
20th Jul 2020, 7:34 AM
Théophile
Théophile - avatar