1.const 与#define的区别
#define:
--1.预编译(编译前处理)
--2.宏能定义一些函数和方法,const不能,但是大量使用宏会加长编译时间,
--3.宏不会做编译检查


const:
--1.编译阶段处理
--2.const 会做编译检查
--3.const 仅仅是修饰右边 的变量(只能呢个修饰变量,基本变量,指针变量,对象变量)
--4.const 修饰的变量,表示只读,不可修改
const 修饰基本变量

const修饰指针变量

2.static 和 extern 的使用
static 的作用
--1.修饰局部变量(
1.会延长该局部变量的生命周期,只要程序运行就会分配一次内存,局部变量会一直存在;

2.该局部变量只会分配一次内存

--2.修饰全局变量
只会修改全局变量的作用域,表示只能是当前文件内使用
Extern 的作用
声明一个全局变量,不能定义变量
注意 extern 修饰的变量不能初始化
一般用于声明全局变量
网友评论