2024年10月9日 09:09

This commit is contained in:
许大仙 2024-10-09 01:09:29 +00:00
parent af4b82c4ba
commit 013717e57e

View File

@ -855,6 +855,16 @@ int main() {
## 2.6 #defind 定义常量 VS const 定义常量
* #defind 定义常量 和 const 定义常量的对比,如下所示:
| 类别 | 说明 |
| -------- | ---- |
| 执行时机 | |
| | |
| | |
* ① 执行时机:`#define` 是预处理指令,在编译`之前`执行;`const` 是关键字,在编译`过程`中执行。
* ② 类型检查:`#define` 定义常量`不用指定类型``不进行类型检查`,只是简单地文本替换;`const` 定义常量`需要指定数据类型``会进行类型检查`,类型安全性更强。