【C++】const 关键字

想要正确理解const关键字,只需记住一句话:

cosnt关键字优先修饰左边,如果左边每东西,就作用于右边。

const int a;    修饰int a 不能改变

const int *a ;
int const *a;
修饰int 指针a指向的地址可以改变,但是地址中存的值不能改变。

int *const a ; 修饰* 指针a指向的地址不可以改变,但是地址中存的值可以改变。

const int * const a; 指针a指向的地址不可以改变,但是地址中存的值也不可以改变。

猜你喜欢

转载自blog.csdn.net/holle_world_ldx/article/details/135210518
今日推荐