今天看 OOP in C 的时候碰到了这种声明 Shape const * const me。上网查了一下资料,做个总结。
int *p1; // p1 is a pointer to int
const int *p21; // p21 is a pointer to const int
int const *p22; // p22 is a pointer to const int
int *const p3; // p3 is a constant pointer to int
const int *const p41; // p41 is a constant pointer to const int
int const *const p42; // p42 is a constant pointer to const int
阅读诀窍是从右往左读,直到碰到第一个 *。如果 * 右边有 const,那么这个指针是常量指针。左边的 const 和 int 可以互换。
参考资料:











网友评论