- 定义常量
const int SIZE=71;
const double pi=3.14;
const char* NAME="MOOC";
- 定义常量指针
不能通过常量指针改变它所指向的变量的值
int m,n;
const int*p=m;
*p=5; //编译错误
n=5; //正确
p=&m; //正确
不能把常量指针赋值给非常量指针(除非强制类型转换),反之可以。
- 定义常引用
const int SIZE=71;
const double pi=3.14;
const char* NAME="MOOC";
不能通过常量指针改变它所指向的变量的值
int m,n;
const int*p=m;
*p=5; //编译错误
n=5; //正确
p=&m; //正确
不能把常量指针赋值给非常量指针(除非强制类型转换),反之可以。