什么是#运营商的宏吗? [英] What does the # operator do in macros?
问题描述
#include <stdio.h>
#define foo(x, y) #x #y
int main()
{
printf("%s\n", foo(k, l));
return 0;
}
输出:结果 KL
我知道##做串联。从输出似乎#
也做串联。
我对么?
I know that ## does concatenation. From the output it seems that #
also does concatenation.
Am I correct?
如果我是正确的话是什么之间 ##
运营商和#
运营商?
If I am correct then what is the difference between ##
operator and #
operator?
推荐答案
#
打开参数为一个字符串。因此,美孚(K,L)
变成K,L
,这是一样的KL
因为在C多重字符串是直接相邻的被视为一个单一的字符串。
#
turns the argument into a string. So foo(k, l)
becomes "k" "l"
, which is the same as "kl"
because in C multiple string literals that are directly next to each other are treated as a single string literals.
如果#
并串联,你的printf调用将成为的printf(%S \\ n,KL);
这将产生约误差 KL
没有被定义的。
If #
did concatenation, your printf call would become printf("%s\n", kl);
which would produce an error about kl
not being defined.
这篇关于什么是#运营商的宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!