const与指针
int sloth=3;
const int * ps = &sloth; //a pointer to const int --1
int * const finger = &sloth; //a const pointer to int --2
对于1来说:是一个指针,指向一个const int 类型
不能通过指针来修改sloth的值,但sloth本身可以通过赋值来修改。
可以修改指针的值,即可以使指针指向其他地址。
对于2来说:是一个const指针,指向一个int 类型
不能改变指针指向的地址,也就是指针的值是一个常量,指针只能指向sloth。
可以通过指针修改sloth的值