Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define f(g,g2) g##g2

Tags:

c

#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}

The above program prints 100 in c by concatenating var and 12. How does g##g2 work??

like image 962
Shishir Garg Avatar asked Nov 28 '09 19:11

Shishir Garg


1 Answers

## just pastes tokens together. It is a preprocessor directive.

E.g.

#define PASTE(a,b)  a##b

int i=PASTE(1,2);  /* int i=12; */
like image 54
jldupont Avatar answered Nov 10 '22 14:11

jldupont