## operator

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();
}

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
## 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.