字符串化运算符#

#define SQR(x) printf("the squar of x is %d\n",((x)*(x)))

如果直接调用SQR(8),则输出the squar of x is 64

也就是“”中的字符x被当作普通字符来处理,没有被8替换掉

 

修改宏定义如下:

#define SQR(x) printf("the squar of “#x ”is %d\n",((x)*(x)))

再调用SQR(8),则输出the squar of 8 is 64

#的作用就是可以把语言符号转换为字符串

posted @ 2012-11-22 12:11  枫部落  阅读(193)  评论(0编辑  收藏  举报
点击这里给我发消息