Can anyone explain why the output is 10 and not 15 ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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; }

10th Feb 2022, 9:00 AM
SHIVANSH MITTAL
SHIVANSH MITTAL - avatar
2 Answers
+ 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
10th Feb 2022, 9:22 AM
Jayakrishna 🇮🇳
10th Feb 2022, 9:18 AM
Slick
Slick - avatar