C语言常量定义#define和const区别解析

定义常量的两种方式:预处理器#define和const关键字

#define PI 3.14//#define 常量名 常量值
const double PI=3.14;//const 数据类型 常量名=常量值

无论define还是const都不能再进行更改值
const带数据类型,#define不带数据类型
const是在编译(.obj)运行时起作用,#define在编译前的预处理阶段就起作用;因此const可以进行调试,define不可以

重要实例

#include
#define

你可能感兴趣的:(数据变量和常量,define,const,c++,指针,c语言,数据结构)