+ 8

why output is 3 why why why

// why output is 3 why why why ??? #include <stdio.h> #define square(r) (r*r) int main() { int y = 1; printf("Area is %d\n", square(y+1)); return 0; }

11th May 2020, 5:46 AM
Ashutosh k.
Ashutosh k. - avatar
3 odpowiedzi
+ 13
The macro is : square(1) (1+1*1+1) So according to operator precedence, multiplication has higher precedence than addition. So first 1*1 is evaluated then addition is done. So 1+(1*1)+1 = 1+1+1 = 3
11th May 2020, 5:51 AM
Nova
Nova - avatar
+ 6
Thanks nova
11th May 2020, 5:53 AM
Ashutosh k.
Ashutosh k. - avatar
+ 4
It will be calculate like this square(1) (1+1*1+1) So 1+(1*1)+1 = 1+1+1 = 3
11th May 2020, 10:09 AM
A S Raghuvanshi
A S Raghuvanshi - avatar