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
1 Odpowiedź
+ 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