c语言定义宏 #define call(x,y) x##y表示什么?

2025-02-05 19:38:16
推荐回答(4个)
回答1:

c语言中,##表示把两个宏参数贴合在一起,即,
#define call(x,y) x##y ,执行call(x,y)结果为xy,例如,
int x=2,y=5;
int xy=90;
printf("%d\n",call(x,y));//结果为90

##被称为连接符,用来将两个宏参数连接为一个宏参数。
而单个#的功能是将其后面的宏参数进行字符串化操作,简单地说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号,使其成为字符串。

回答2:

#define call(x,y) x##y

##把x和y连接起来,相当于新变量xy

xy+call(x,y) 就相当于xy+xy=20+20=40;

参考资料:
The preprocessor operator ## provides a way to concatenate actual arguments during macro
expansion. If a parameter in the replacement text is adjacent to a ##, the parameter is replaced
by the actual argument, the ## and surrounding white space are removed, and the result is rescanned.
For example, the macro paste concatenates its two arguments:
#define paste(front, back) front ## back
so paste(name, 1) creates the token name1.

回答3:

## 连接符号由两个井号组成,其功能是在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串。

call(x,y) 的意思就是 xy
即 xy+call(x,y) = xy+xy = 20 + 20 = 40

回答4:

从未听说过