c - #define Printf() 字符串中的预处理器替换

标签 c string macros printf c-preprocessor

我正在打印一个字符串,例如:

printf("Print the number thirty: 30\n"); 

如果我做出以下定义

#define THIRTY 30

现在

printf("Print the number thirty: THIRTY"); 

C 预处理器是否会替换字符串中的 THIRTY --> 30

或者我必须去:

printf("Print then number thirty: %d", THIRTY); 

最佳答案

C 预处理器不理解字符串内部的内容,因此不会操作字符串。

以下语句会将 THIRTY 替换为 30

printf("Print then number thirty: %d", THIRTY);  

关于c - #define Printf() 字符串中的预处理器替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33010908/

相关文章:

c - 如何在C中检测未初始化的字符串

macros - Julia 宏中的无效赋值错误

emacs - 无法使用 make-symbol 生成的名称调用宏中定义的函数

error-handling - 在 defmacro 中指示错误的常规方法是什么?

c - WinApi C 多线程 : how to wait for a thread to finish?

c - NULL + int 的结果是什么?

C变量类型断言

c++ - 使用 WinAPI 规范化文件路径

c - 将一个字符附加到一个字符 *

c# split string in 2. 逐个字母