C语言中的宏常量
Jihongchang(讨论 | 贡献)2022年10月28日 (五) 10:18的版本
https://www.bilibili.com/video/BV1vR4y1H7MY/?p=10
C语言的常量分为
- 字面常量
- 用 #define 定义的宏常量:可以用 #define 定义一个标识符来表示一个常量。其特点是:定义的标识符不占内存,只是一个临时的符号,预编译后这个符号就不存在了。
- 用 const 关键字修饰的变量,称为常变量
- 枚举常量
- 字符常量和字符串常量
#include<stdio.h>
#define LEN 100
#define PI 3.14
int main()
{
int a = LEN;
float r = 10, s = 0;
s = r * r * PI;
printf("s = %f \n", s);
return 0;
}
#define 只要一个作用,就是 替换。
#include 是 包含。
宏常量在预编译时进行替换: