1,const修饰变量———— 常变量
const int a=10;
a=1;错误:因为被const修饰的变量是常变量,即a为不可修改的左值。
2,const修饰指针———— 常量指针,指针常量
int a=10;
int b=20;
const int* p=&a; 常量指针
*p=20;错误:因为const修饰*p,表示指针指向的值不可以改变。
p=&b;正确:指针的指向可以更改。
3,int* const p =&a; 指针常量
*p=20;正确:表示指针指向的值可以更改;
p=&b;错误:const修饰的是指针变量p,所以指针的指向不可以更改。
4,即修饰指针,又修饰常量:
const int* const p =&a;表示指针的指向和指向的值都不可以更改。