zoukankan      html  css  js  c++  java
  • c语言"##"的使用

    #include<stdio.h>
    #define Operations(x) operation_ ## x  // ## 是黏贴字符串
    
    int Operations(sum)(int x,int y){  // operation_sum(int x,int y)
        return x+y;
    }
    
    int Operations(sub)(int x,int y){  // operation_sub(int x,int y)
        return x-y;
    }
    
    int Operations(mul)(int x,int y){  // operation_mul(int x,int y)
        return x*y;
    }
    
    float Operations(div)(float x,float y){  // operation_div(int x,int y)
        float result;
        result =x/y;
        return result;
    }
    
    #define Print(x) printf("%s,%d
    ",#x,x);  // # 表示将参数转变为字符串
    int main()
    {
        int x;
        float y;
        x=Operations(sum)(10,20);
        printf("x=%d
    ",x);
        x=operation_sum(100,20);
        printf("x=%d
    ",x);
        x=Operations(sub)(10,20);  // operation_sub(10,20)也可以
        printf("x=%d
    ",x);
        x=Operations(mul)(10,20);  // operation_mul(10,20)也可以
        printf("x=%d
    ",x);
        y=Operations(div)(11,20);  // operation_div(11,20)也可以
        printf("y=%lf
    ",y);
        Print(100);
        return 0;
    }

    注:##连接两边字符串。

  • 相关阅读:
    HashMap源码分析jdk1.8
    Struts1.x总结
    session的使用
    浅谈EL
    浅谈JavaBean
    try、catch、finally带return的执行顺序总结
    jvm内存模型
    left join 、right join 、inner join之间的区别
    js按键事件
    log4j配置详解
  • 原文地址:https://www.cnblogs.com/ligei/p/11536448.html
Copyright © 2011-2022 走看看