问答题 #define TRACE(S)(printf("%s/n",#s),s)是什么意思
【正确答案】
【答案解析】#进行宏字符串连接,在宏中把参数解释为字符串,不可以在语句中直接使用。在宏定义中printf("%s/n",#S)会被解释为printf("%s/n","S")。
程序示例如下:
#include<stdio.h>
#include<string.h>
#define TRACE(S)(prinff("%s/n",#S),S)
int main()
{
int a=5;
int b=TRACE(a);
const char *str="hello";
char des[50];
strcpy(des,TRACE(str));
printf("%s/n",des);
return 0;
}
程序输出结果:
a
str
hello
上例中,宏定义又是一个逗号表达式,所以复制到des里面的值为后面S,也就是str的值。所以最后输出的就是字符串“hello”了。