#运算符
#运算符用于在预编译期将宏参数转换为字符串
#define CONVERS(x) #x
printf(‘%s\n”,CONVERS(Hello world!));

CONVERS(100)
CONVERS(while)

#define CALL(f,p) (printf(“Call function %s”,#f),f(p))
int square(int n)
{
return n*n;
}
int f(in x)
{
return x;
}
int main()
{
printf(“1. %d\n”,CALL(square,4));
printf(“2.%d\n”,CALL(f,10));
return 0;
}

运算符

运算符用于在预编译期粘连两个符号

include

define NAME(n) name##n

int main()
{
int NAME(1);
int NAME(2);
NAME(1)=1;
NAME(2)=2;
printf(“%d\n”,NAME(1));
printf(“%d\n”NAME(2));
return 0;
}

利用##定义结构体类型
#define STRUCT(type) typedef struct_tag_##type type;\
struct tag##type

STRUCT(Student)
{
char * name;
int id;
}
C语言#和##运算符的用法

这样就不用写6个函数了

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-09-11
  • 2021-09-27
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2021-12-05
  • 2021-12-05
  • 2021-11-30
  • 2022-01-16
相关资源
相似解决方案