# Preprocessor Macro Operator

The # (single number sign) operator converts a parameter of a function-like macro into a character string literal. For example, if macro ABC is defined using the following directive:

#define ABC(x)   #x

all subsequent invocations of the macro ABC would be expanded into a character string literal containing the argument passed to ABC. For example:

Invocation Result of Macro Expansion
ABC(1) "1"
ABC(Hello there) "Hello there"

The # operator should not be confused with the # null directive.

Use the # operator in a function-like macro definition according to the following rules:

The following example demonstrates the use of the # operator:

Sample Preprocessor Macro Definitions
#define STR(x) #x
#define XSTR(x) STR(x)
#define ONE 1
Invocation Result of Macro Expansion
STR(\n "\n" '\n') "\n \"\\n\" '\\n'"
STR(ONE) "ONE"
XSTR(ONE) "1"
XSTR("hello") "\"hello\""

 



Preprocessor Directives
Preprocessor Macros


Preprocessor Macro Operators
#define Preprocessor Directive