最近在APUE上看到了个字符串创建运算符(#),到网上搜索了下用法,写了个小程序,一看便懂(好像只能在宏下使用)
简单说就是将标识符变成字符串:
#include <stdio.h>
#include <string.h>
#define doit(name) pri(#name)
int pri(char *name)
{
printf("%s\n",name);
}
int main()
{
char key[20];
strcpy(key,"Helloc");
pri(key);
doit(key);
doit(HELLO);
}
输出结果:
Helloc
key
HELLO