The ##
concatenates two tokens together.
The important thing is it can only be used in the preprocessor.
The #
operator is used to stringify tokens.
For example:-
#(a ## b)
which becomes #ab
which becomes "ab"
So h(f(1,2)) becomes "f(1,2)"
Also note that #
and ##
are two different operators.
The preprocessor operator ## provides a way to concatenate actual
arguments during macro expansion. If a parameter in the replacement
text is adjacent to a ##, the parameter is replaced by the actual
argument, the ## and surrounding white space are removed, and the
result is re-scanned.
Also check this Concatenation for more details.
From here:-
Stringification
Sometimes you may want to convert a macro argument into a string
constant. Parameters are not replaced inside string constants, but you
can use the '#' preprocessing operator instead. When a macro parameter
is used with a leading `#', the preprocessor replaces it with the
literal text of the actual argument, converted to a string constant.
Unlike normal parameter replacement, the argument is not
macro-expanded first. This is called stringification.
There is no way to combine an argument with surrounding text and
stringify it all together. Instead, you can write a series of adjacent
string constants and stringified arguments. The preprocessor will
replace the stringified arguments with string constants. The C
compiler will then combine all the adjacent string constants into one
long string.