The ## (double number sign) operator concatenates two tokens in a macro invocation (text and/or arguments) given in a macro definition.
If a macro XY was defined using the following directive:
#define XY(x,y) x##y
the last token of the argument for x is concatenated with the first token of the argument for y.
For example,
| Invocation | Result of Macro Expansion |
|---|---|
"XY(1, 2)" |
"12" |
"XY(Green, house)" |
"Greenhouse" |
Use the ## operator according to the following rules:
/**/ Operator
The /**/ operator differs from the ##
operator only in the way that the preprocessor preserves white
spaces between the operator and its arguments.
For example, the macro definition:
#define XY(x, y) x /**/y // will result in x y
does not give the same result as:
#define XY(x, y) x ##y // will result in xy
With the ## operator, arguments are concatenated without white space.
In ANSI/ISO C, for the /**/ to function the same way
as ##, there can be spaces between the operator and the
arguments.
![]()
Preprocessor
Directives - An Overview
![]()
# Operator
Macro Definition
and Expansion - #define
Scope of Macro
Names - #undef
Example
of Preprocessor Directives
