0

Not able to understand output

#include <stdio.h> #define prod(i,j) i*j int main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); return 0; } Output is 10 #include <stdio.h> #define prod(i,j) i*j int main() { int x=3,y=4; printf("%d",prod((x+2),(y-1))); return 0; } Output is 15

30th Sep 2019, 9:19 AM
Ahsan Ali Khan
Ahsan Ali Khan - avatar
1 ответ
+ 3
It's because of operation precedence and because "define" simply substituted i with x+2 and j with y-1. Using the parentheses in the second program you force multiplication to follow addition/subtraction. In the first program: x+2*y-1=3+2*4-1=10 In the second program: (x+2)*(y-1)=5*3=15
30th Sep 2019, 9:46 AM
AndreaC
AndreaC - avatar