宏参数创建字符串

#include <iostream>
// printf()返回值为输出打印字符的个数
// 利用宏参数创建字符串
#define SQUARE(x) (printf(""#x"  square is: %d\n", (x) * (x)))

int main()
{
    
    
    SQUARE(2+4);
}
  • 也可以这么写
#include <iostream>
// printf()返回值为输出打印字符的个数
// 利用宏参数创建字符串
#define SQUARE(x) (printf("%d  square is: %d\n",(x), (x) * (x)))

int main()
{
    
    
    SQUARE(2+4);
}

猜你喜欢

转载自blog.csdn.net/m0_69841436/article/details/141403519