zoukankan      html  css  js  c++  java
  • C/C++宏定义中#与##区别

     1     // #表示:对应变量字符串化  
     2     // ##表示:把宏参数名与宏定义代码序列中的标识符连接在一起,形成一个新的标识符  
     3     #include <stdio.h>  
     4     #define trace(x, format) printf(#x " = %" #format "
    ", x)  
     5     #define trace2(i) trace(x##i, d)  
     6       
     7     int main()  
     8     {  
     9         int i=1;  
    10         char *s="three";  
    11         float x=2.0;  
    12       
    13         trace(i, d);                // 相当于 printf("i = %d
    ", x) ,输出结果:i = 1
    14         trace(x, f);                // 相当于 printf("x = %f
    ", x) ,输出结果:x = 2.000000
    15         trace(s, s);                // 相当于 printf("s = %s
    ", x) ,输出结果:s = three
    16       
    17         int x1=1, x2=2, x3=3;  
    18         trace2(1);              // 相当于 trace(x1, d),输出结果:x1 = 1  
    19         trace2(2);              // 相当于 trace(x2, d),输出结果:x2 = 2 
    20         trace2(3);              // 相当于 trace(x3, d),输出结果:x3 = 3
    21       
    22         return 0;  
    23     } 
  • 相关阅读:
    Java 插入排序
    Java 浮点型与双精度数值比较
    Java 包装类Integer的值比较
    ORA-00942 table or view does not exist
    logging模块
    面向对象
    模块和包
    异常处理
    序列化模块
    css3选择器
  • 原文地址:https://www.cnblogs.com/deityde1127/p/6722229.html
Copyright © 2011-2022 走看看