参考:# 和 ## 的区别
作者:枕上
发布时间:2021-07-25 08:23:40
网址:https://blog.csdn.net/jinchi_boke/article/details/119076280?utm_source=app&app_version=4.11.0&code=app_1562916241&uLinkId=usr1mkqgl919blen
#:
1、最常见的是 #不会替换参数,只替换其所对应的字符
2、 把宏参数变成一个字符串;
##:
把两个宏参数连接到一起(只能两个)
Demo:
#include <stdio.h>
#include <stdlib.h>
#define ONE 1 //1.最常见的是 #不会替换参数,只替换其所对应的字符;
#define toString(str) #str //2.转字符串
#define hehe(x,y) x##y //连接
int main()
{
printf("%d\n",ONE); //#不会替换参数,只替换其所对应的字符;
printf(toString(123456)); //输出字符串"123456"
printf("\n %d \n",hehe(1,2)); //输出 int 12
char string[]="hello world!";
puts(hehe(str,ing));
printf("%s\n",hehe(str,ing));
system("pause");
return 0;
}
输出结果:
1
123456
12
hello world!
hello world!