在带参的宏定义中,#运算符后面应该跟一个参数,预处理会把这个参数转换成一个字符串;
#include <stdio.h>
#define STR(s) # s
int main()
{
printf("%s\n", STR(Hello World));
}
#号会把传递的参数转换成字符串;
#include <stdio.h>
#define STR(s) # s
int main()
{
printf("%s\n", STR("Hello World"));
}
如果参数有双引号,会被替换成/“。
#include <stdio.h>
#define STR(s) # s
int main()
{
printf("STR(ABC %s %s)\n", STR(Hello World),"!!!");
}
##记号连接运算符,连接两个参数;
#include <stdio.h>
#define STR(s1,s2) s1 ## s2
int main()
{
printf("%d\n", STR(1 ,2));
}