指针常量 常量指针

const int b=10; 和int const b=10 是一样的

1.  const放在 *前面     常量指针

   int const *p;  

   const int *p;

不能通过p修改变量的值

const 修饰的是*p  表明 *p(值)不能修改

2. const放在 *后面        指针常量

   int * const p;  一开始要赋值,  不能被修改,  是一个常量, 也不能p++;

 const  修饰的是q  表明q(指向)不能修改

const  常量  * 指针   

先const再*    则是 常量指针

先*再const   则是 指针常量

猜你喜欢

转载自blog.csdn.net/Mr_HCW/article/details/81676123