Name

The ## Operator

Synopsis

If a macro parameter appears in the replacement text preceded or followed by the operator ## (called the double-hash or token-pasting operator), then the preprocessor concatenates the tokens to the left and right of the operator, ignoring any spaces. If the resulting text also contains a macro name, then macro replacement is performed once again.

Example:

#define show( var, num )  \
       printf( #var #num " = %.1f\n", var ## num )

If the float variable x5 has the value 16.4, then the macro invocation:

show( x, 5 );

is replaced with:

printf( "x" "5" " = %.1f\n", x5 ); 
// Output: x5 = 16.4\n

Get C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.