## operator
Oct 26, 2012 at 2:21pm UTC
i compiled the following code and got my output as 100.I am not able to understand the logic behind this...basically the meaning of ## operator...please help me with this
1 2 3 4 5 6 7
#include <stdio.h>
#define f(g,g2) g##g2
main()
{ int var12=100;
printf("%d" ,f(var,12));
getchar();
}
Oct 26, 2012 at 2:23pm UTC
Examine the preprocessor output before compilation. It looks like this:
1 2 3 4 5
main()
{ int var12=100;
printf("%d" ,var12);
getchar();
}
## is not an operator.
f(var,12)
gets turned into
var12
This is a (pretty pointless) preprocessor macro.
Last edited on Oct 26, 2012 at 2:24pm UTC
Oct 26, 2012 at 2:26pm UTC
## is a preprocessor directive. It pastes two tokens together. So
f( var, 12 ) is replaced by var12.
After the preprocessing the code will look as
1 2 3 4 5
main()
{ int var12=100;
printf("%d" ,var12);
getchar();
}
Topic archived. No new replies allowed.