c语言宏定义展开顺序例题

  本文原创,版权属作者个人所有,如需转载请联系作者本人。Q&微:155122733

--------------------------------------------------------------------------------------------------------

涉及到宏定义展开顺序的知识,如果宏替换以# ##为前缀 ,则由外向内展开

1 #define f(x) #x //结果将被扩展为由实际参数替换该参数的带引号的字符串
2 #define b(x) a##x //连接实际参数
3 #define ac hello
4 int main(void)
5 {
6     f(b(c))//display "b(c)"
7 }

如果最外层p(x)宏替换不以# ##为前缀,则由内向外展开

#define f(x) #x
#define p(x) f(x)
#define b(x) a##x
#define ac hello
int main(void)
{
    p(b(c))// display "hello"
    return 0;
}
原文地址:https://www.cnblogs.com/lcl0421/p/8891631.html