C 语言中##与#的作用

来源:互联网 发布:淘宝舒口健竹盐牙膏 编辑:程序博客网 时间:2024/05/01 15:28


编程技巧:

##连接符号,用在带参数的宏定义中将两个子串在编译时候联接起来,组成一个新的字串。但是不可以把##符放在字串最前面或最后面

#则表示 对这个变量替换后,再加双引号引起来


测试用例:
#include <stdio.h>#define PREFIX0(module)       10##module#define PREFIX1(module)       "hello"#modulevoid  main(void){    printf ("test_int=%d\n",PREFIX0(9));    printf ("test_string=%s\n",PREFIX1(world));}


测试结果:
test_int=109test_string=helloworld



0 0
原创粉丝点击