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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.