0

In challenge answers are wrong

#define square (x) x*x printf ("%d",square (4+1)); choices: 4 9 5 25 I have chosen result 25 but it shows that the result is 9. Am I wrong with result 25?

12th Jun 2019, 9:02 AM
#멜젠
#멜젠 - avatar
13 Answers
+ 3
It would be 4+1*4+1 Due operator precedence of * multiplication takes place first =>4+4+1=9
12th Jun 2019, 9:19 AM
Tony Stark
Tony Stark - avatar
+ 3
What Tony Stark means is that the sum would be processed like this: Multiplication first: 1*4 = 4 Then addition: 4 + 4 + 1 = 9
12th Jun 2019, 9:38 AM
Rincewind
Rincewind - avatar
+ 1
No it's 9
12th Jun 2019, 9:21 AM
Tony Stark
Tony Stark - avatar
+ 1
Ah yes, I missed that it was in C so it isn't BODMAS, the logic remains the same though.
12th Jun 2019, 12:37 PM
Rincewind
Rincewind - avatar
+ 1
Thank you for each of you
12th Jun 2019, 12:52 PM
#멜젠
#멜젠 - avatar
0
Tony Stack so result 25?
12th Jun 2019, 9:21 AM
#멜젠
#멜젠 - avatar
0
Yes
12th Jun 2019, 9:39 AM
Tony Stark
Tony Stark - avatar
0
Thanks Anna
12th Jun 2019, 12:06 PM
#멜젠
#멜젠 - avatar
0
Rincewind compiler doesn't follow BODMAS rule... It computes based on operator precedence & associativity
12th Jun 2019, 12:23 PM
DHANYAMBIKA B
DHANYAMBIKA B - avatar
0
So result 25?
12th Jun 2019, 12:45 PM
#멜젠
#멜젠 - avatar
0
No result is 9
12th Jun 2019, 12:48 PM
#멜젠
#멜젠 - avatar
0
Now I got
12th Jun 2019, 12:48 PM
#멜젠
#멜젠 - avatar