const* 与*const

1.指向常量的指针和指针常量

    int a=0;
    const int *const p=&a;
//    *p=2;//error: assignment of read-only location '*(const int*)p'
    int *const p1=&a;
    *p1    =3;//正确

在p的生命中,从左往右的第一个const说明,它不能改变a中的值,第二个const说明它不能指向别的对象。

 

posted @ 2020-10-29 20:11  lypbendlf  阅读(179)  评论(0编辑  收藏  举报