+ 6

How the answer is 9 for this code?

#include <stdio.h> #define square(x) x * x int main() { printf("%d", square(4+1)); return 0; }

5th Feb 2022, 4:40 PM
Ctrl + Z
Ctrl + Z - avatar
2 Respostas
+ 11
Square (x) is x * x So if we pass 4+1 as x This is how things happens here S1: 4+1*4+1 S2: as the * has high precedence than + from left to right 1*4 = 4 S3: 4+4+1 = 9 Precedence matters a lot If u use square (x) (x)*(x), you'll get 25 as answer Because (4+1)*(4+1) -> 5*5 = 25 Hope you understand.
5th Feb 2022, 4:45 PM
GURURAJ KL
GURURAJ KL - avatar