Fork me on GitHub

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

1.##:用于拼接操作

实例:

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

int main() {
    int res = CONCAT(1, 2);
    printf("%d\n", res);
    char* ptr = CONCAT("nihao!","zaijian");
    printf("%s\n", 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\n",typeid(ptr).name());
    system("pause");
    return 0;
}
posted @ 2020-01-01 15:06  西西嘛呦  阅读(697)  评论(0编辑  收藏  举报