int a = 4;
int const * p = &a;//const int * q = & a;
//p是指向一个常量的指针(指针可变)
cout<<"the value of *p is "<<*p<<endl;
//修改p的指针的值
int b = 5;
p = &b;//OK
cout<<"change the pointer of p,the value is "<<*p<<endl;
//修改指针p所指向的值
//*p = 12;//ERROR
int c = 6;
int * const pp = &c;
//指向整形的常量指针(指针不可变)
*pp =23;//OK
pp = & a;//ERROR
int const * const qq = &c;
//* pp = 44;//ERROR
//pp = &a;//ERROR
const修饰指针 变量
最新推荐文章于 2021-04-29 19:38:28 发布