什么是宏

2018-04-08  本文已影响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;
}

上一篇下一篇

猜你喜欢

热点阅读