c语言之宏定义中的##和#

1.##:用于拼接操作

实例:

#include<stdio.h>
#include<iostream>
#define CONCAT(parm1,parm2) (parm1##parm2)

int main() {
    int res = CONCAT(1, 2);
    printf("%d
", res);
    char* ptr = CONCAT("nihao!","zaijian");
    printf("%s
", ptr);
    system("pause");
    return 0;
}

2.#:用于将参数进行字符串化

#include<stdio.h>
#include<iostream>
#include<typeinfo>
#define TO_STRING(parm) #parm

int main() {
    char* ptr = TO_STRING(110);
    printf("%s
",typeid(ptr).name());
    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/xiximayou/p/12128923.html