#运算符
1、#运算符用于在预编译期将宏参数转换为字符串
#include <stdio.h>#define message(X) #X#define CALL(f,p) (printf("This is fuction %s\n",#f),f(p))int square (int n)
{return n*n;
}int main()
{printf("%s\r\n",message(hello));printf("大家猜一猜这句是怎么打印的 %d\n",CALL(square,4));}
2、##预算符用于在编译期粘连两个符号
很好的示例(来源于网络)
#include <stdio.h>#define STRUCT(type) typedef struct _tag_##type type;\
struct _tag_##typeSTRUCT(Student)
{char* name;int id;
};int main()
{Student s1;Student s2;s1.name = "s1";s1.id = 0;s2.name = "s2";s2.id = 1;printf("%s\n", s1.name);printf("%d\n", s1.id);printf("%s\n", s2.name);printf("%d\n", s2.id);return 0;
}