#include<iostream>
int func(int, int);
#define func(x,y) x/y+x
int main()
{
int i, j;
scanf("%d", &i);
scanf("%d", &j);
printf("%d ", func(i + j, 3));
printf("%d\n", func(i + j, 3));
}
int func(int x, int y) {
return y / x + y;
}
What should be added to this code so that the 1st output is the result of the macro and the 2nd one is the result of the function?
Several ways:
printf("%d ", func(i + j, 3)); // Macro call
#undef func // Macro is no longer defined
printf("%d\n", func(i + j, 3)); // Function call
or
printf("%d ", func(i + j, 3)); // Macro call
printf("%d\n", (func)(i + j, 3)); // Function call
Yet another way:
#define EMPTY
printf("%d\n", func EMPTY (i + j, 3));
Seen in Boost.PP, the EMPTY
macro "burns up" the expansion iteration and the resulting func(...)
is left untouched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With