C/C++宏定义中#与##区别
2015-07-08 10:00
204 查看
【转载自】:http://blog.csdn.net/huang_xw/article/details/7648179
[code] // #表示:对应变量字符串化 // ##表示:把宏参数名与宏定义代码序列中的标识符连接在一起,形成一个新的标识符 #include <stdio.h> #define trace(x, format) printf(#x " = %" #format "\n", x) #define trace2(i) trace(x##i, d) int main() { int i=1; char *s="three"; float x=2.0; trace(i, d); // 相当于 printf("x = %d\n", x) trace(x, f); // 相当于 printf("x = %d\n", x) trace(s, s); // 相当于 printf("x = %d\n", x) int x1=1, x2=2, x3=3; trace2(1); // 相当于 trace(x1, d) trace2(2); // 相当于 trace(x2, d) trace2(3); // 相当于 trace(x3, d) return 0; }
相关文章推荐
- 【c语言】数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字
- quick_sort(快速排序)c语言实现
- c++训练题(牵扯到大数据的保存)
- C++知识点随笔(四):耦合问题、new和malloc、虚析构、多继承
- C++编写Windows服务
- 【C语言】调整数组使奇数全部都位于偶数前面(修改)
- C++实现简单的学生管理系统
- 【c语言】调整数组使奇数全部都位于偶数前面
- C语言统计字符个数代码分享
- C语言获取消耗内存的方法
- C++文件读写代码分享
- 有关C++的拷贝构造函数
- C和C++内存模型
- C语言进制转换代码分享
- D24 复习C语言
- c++读书笔记——多重继承
- C++读书笔记——静态与动态绑定
- C++面试题by hht
- [C++]字节对齐与结构体大小
- c语言中的指针