- 1
Can anyone explain why the output is 10 and not 15 ??
#include <stdio.h> #define prod(i,j) i*j int main() { int x=3,y=4; printf("%d",(x+2,y-1)); return 0; }
2 Réponses
+ 5
#include <stdio.h>
#define prod(i,j) i*j
int main()
{
int x=3,y=4;
printf("%d",prod(x+2,y-1)); //you missed to typed here
return 0;
}
prod(x+2,y-1)) interpreted as :
x+2 * y-1
=> 3+2 * 4-1 // * has highest precedence
=> 3+ 8 -1
=> 10
your expectation is true if it is
#define prod(i,j) (i)*(j)
then its
=>(x+2)*(y-1)
=>(3+2) * (4-1)
=> 5*3= 15
+ 5
Order of operations dude
https://code.sololearn.com/ch2HULC5M2sT/?ref=app
Use parenthesis
https://code.sololearn.com/cqkPAVBcUuV6/?ref=app