# 的用法
今天看华为笔记题的时候,看到这个表达示
#define print(x) printf("the no,"#x",is")
请问这里的#号是怎么用的?
[解决办法]
预编译器把它连成一个字符串了。
[解决办法]
print(10)
展开之后就是
printf( "the no, " "10 " ",is ");
[解决办法]
就是“填空”
[解决办法]
这个就是带参数的宏定义,在编译过程中直接拿参数填入替换。
[解决办法]
可以 参考 MSDN Preprocessor Operators 一节
Preprocessor Operators
Four preprocessor-specific operators are used in the context of the #define directive (see the following list for a summary of each). The stringizing, charizing, and token-pasting operators are discussed in the next three sections. For information on the defined operator, see The #if, #elif, #else, and #endif Directives.
Operator Action
Stringizing operator (#) Causes the corresponding actual argument to be enclosed in double quotation marks
Charizing operator (#@) Causes the corresponding argument to be enclosed in single quotation marks and to be treated as a character (Microsoft Specific)
Token-pasting operator (##) Allows tokens used as actual arguments to be concatenated to form other tokens
defined operator Simplifies the writing of compound expressions in certain macro directives