#运算符在宏中做什么?

Pan*_*ato 5 c macros

#include <stdio.h>

#define foo(x, y) #x #y

int main()
{
    printf("%s\n", foo(k, l));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:
kl

我知道##会连接.从输出看来,它似乎#也是连接.我对么?

如果我是正确的那么##运营商和#运营商之间有什么区别?

sep*_*p2k 1

#将参数转换为字符串。所以foo(k, l)变成"k" "l",这与 C 中相同,"kl"因为在 C 中直接相邻的多个字符串文字被视为单个字符串文字。

如果#进行串联,您的 printf 调用将产生一个有关未定义的printf("%s\n", kl);错误。kl