+ 7
I didn't get this program, why it returns 9 but not 25
#define square(x) x*x Int main() { printf("%d", square (4+1)); return 0; }
13 Respostas
+ 18
It is working like this : 4+1*4+1=4+4+1=9
+ 11
If you want your output to be 25:
#define square(x) (x)*(x)
int main()
{
printf("%d", square (4+1));
return 0;
}
// this returns 25 because (x) = (4+1) = (5) and not the way Abhay has point out
// (x)*(x) = (5)*(5)
// parenthesis have higher priority than most of the operations.
+ 8
Surkhab Khan
If there is brackets like this square(x) (x) * (x) then output will be 25
+ 5
I Am AJ ! that's what i meant if there is parenthesis included then the o/p is 25
if no parenthesis is included like so
x*x then it will be executed like you and Abhay said as follow
4 + 1 * 4 + 1 = 4 + 4 + 1 which is indeed 9.
+ 4
Sorry Surkhab I was wrong.
It is like this
square(x) = x * x
square(4 + 1) = 4 + 1 * 4 + 1 = 4 + 4 + 1 = 9
+ 4
RKK
See his question again there is no brackets in macros so output will be 9
Surkhab Khan
Understand here when it's 25 and when it's 9
https://code.sololearn.com/cR1y8UCa5HC1/?ref=app
+ 2
Surkhab Khan its 25 not 9
check it
#include <stdio.h>
#define square(x) (x)*(x)
int main()
{
printf("%d", square (4+1));
return 0;
}
+ 2
I Am AJ ! Thanks sir ....... I got this
+ 1
I Am AJ ! but machine returns o/p 9 ....how
+ 1
Abhay thanks bro
0
RKK machine returns 9 đ€đ€
0
by precedence the multiplication goes first and then the addition
put parentheses in the sum
#define square(x) x*x
Int main()
{
printf("%d", square ((4+1)));
return 0;
}
0
According to (B,O,D,M,A,S) rule ,
Answer would be,
4+1*4+1= 4+4+1= 9
If , you will use brackets (4+1)*(4+1) ,then your and would be 25 ..