I am facing a problem with understanding the use of macro function calls from within a printf() statement.
I have the code below :
#include<stdio.h>
#define f(g,h) g##h
main()
{
printf("%d",f(100,10));
}
This code outputs "10010" as the answer.
I have learned that macro function call simply copy pastes the macro function code in place of the call with the arguments replaced.
So the code should be like :
#include<stdio.h>
#define f(g,h) g##h
main()
{
printf("%d",100##10);
}
But when i executed the above code separately with substituted macro,i get a compilation error.
So how does the first code gives 10010 as the answer while the second code gives a compilation error?
The preprocessor concatenation operator ##
is done before the macro is replaced. It can only be used in macro bodies.
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