美文网首页
什么是宏

什么是宏

作者: 张俊凯 | 来源:发表于2018-04-08 18:53 被阅读1次

    定义:

    英文名为macroinstrunction,简称为macro,直译为大跨度指令,宏观指令,是一段代码或者一个值的别名(a name given to a piece of code or a value)

    用途

    在编程过程中,用来简化重复出现的代码或者变量,增加开发效率和代码的可读性。

    示例代码 (简化变量)

    
    #include <stdio.h>
     
    #define PI 3.145926
    int main(void)
    {
       float radius, area;
        printf("Enter the radius: ");
        scanf("%d", &radius);
        // Notice, the use of PI
        area = PI*radius*radius;
        printf("Area=%.2f",area);
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:什么是宏

          本文链接:https://www.haomeiwen.com/subject/gbymhftx.html