0

What does # do in C? Especially in #define like this

#define FOO(s) #s
Cano64
  • 237
  • 1
  • 2
  • 8

2 Answers2

1

From MSDN documentation:

The number-sign or "stringizing" operator (#) converts macro parameters to string literals without expanding the parameter definition. It is used only with macros that take arguments. If it precedes a formal parameter in the macro definition, the actual argument passed by the macro invocation is enclosed in quotation marks and treated as a string literal. The string literal then replaces each occurrence of a combination of the stringizing operator and formal parameter within the macro definition.

The page linked above contains some practical examples for comparison.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
1

It makes a string so

#define FOO(s) #s
FOO(hello)

Is the same as

"hello"
James
  • 5,635
  • 2
  • 33
  • 44