0
Explaination for #define function.
#define sqr(X) X*X int main() { printf("%d",sqr(3+1)); } Ans = 9 I don't know that how it is executing. please help me anyone here.
3 Respuestas
+ 1
You actually get 7.
Explanation:
3+1 is actually pasted into X, since macros do work like text substitution. So it becomes:
sqr(3+1)=3+1*3+1=7
Solution:
wrap every argument of the macro with parentheses, like:
#define sqr(X) (X)*(X)
In that case it will be:
(3+1)*(3+1)=4*4=16
0
Sir thanks for replay. I tried this program in challenge.But I got that answer as "9".
I just reported as "wrong answer".
0
You're very welcome :)