①const int p;
②const int* p;
③int const* p;
④int * const p;
⑤const int * const p;
⑥int const * const p;
第一种是常量整数,没什么好说的。
后面五种是指针,有一个简便的办法记忆。
从右往左读,遇到p就替换成“p is a ”遇到 * 就替换成“point to”。
比如说②,读作:p is a point to int const.
p是一个指向整型常量的指针。
③读作:p is a point to const int.
意思跟②相同。
④读作:p is a const point to int.
p是一个常量指针,指向整型。
⑤读作:p is a const point to int const.
⑥读作:p is a const point to const int.
⑤和⑥的意思相同,p都是常量指针,指向整型常量。
*前面的是对被指向对象的修饰,*后面的是对指针本身的修饰