Can u plz explain the output......
#include<stdio.h>
#define product(n1,n2) n1*n2
int main()
{
int a,b,c;
a=b=2;
c=product(a+2,b+1);
printf("%d",c);
return 0;
}
output:7
Can u plz explain the output......
#include<stdio.h>
#define product(n1,n2) n1*n2
int main()
{
int a,b,c;
a=b=2;
c=product(a+2,b+1);
printf("%d",c);
return 0;
}
output:7
thanks a lot guys....
c=product(a+2,b+1) will be expanded as
c= 2+2*2+1
Though abhimanipal has already provided the answer I am just trying to explain it a bit....
Since it is a preprocessor macro the values u r passing will first be replaced in proper place and later the calculation will be done at runtime.
Thus,
c=2+2*2+1
c=2+4+1 (Since * is a higher priority operator than +)
c=7
Cheers
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.