belongs to collection: C Preprocessors Programs
We can define a function like Macro, in which we can pass the arguments. When a Macro is called, the Macro body expands or we can say Macro Call replaces with Macro Body.
Consider the example:
#include <stdio.h> #define CALC(X,Y) (X*Y) int main() { printf("%d\n",CALC(1+2, 3+4)); return 0; }
Output
11
Explanation:
If you are thinking that 1+2 and 3+4 will be evaluated before the expansion and it will be expanded as 3*7 then, you are wrong.
The arguments evaluate after the call, thus Macro CALC(1+2,3+4) will be expanded as = (1+2*3+4) = (1+6+4) =(11).
Finally, the output will be 11.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Consider the example:
Output
Explanation:
If you are thinking that 1+2 and 3+4 will be evaluated before the expansion and it will be expanded as 3*7 then, you are wrong.
The arguments evaluate after the call, thus Macro CALC(1+2,3+4) will be expanded as = (1+2*3+4) = (1+6+4) =(11).
Finally, the output will be 11.
need an explanation for this answer? contact us directly to get an explanation for this answer