I want to know the reason behind the output of this code. I couldn’t come up with an answer.
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
void main()
{
printf("%s %s",h(f(1,2)),g(f(1,2)));
}
PS: output is 12 f(1,2). I thought it was 12 12 or f(1,2) f(1,2).
f(1,2)is substituted fora.ais not the subject of a#or##operator so it’s expanded to12. Now you haveg(12)which expands to"12".f(1,2)is substituted fora. The#operator applied toaprevents macro expansion, so the result is literally"f(1,2)".