const指针速记
const 出现在 * 的左边,表示被指物是常量。
例如:const int * a; int const * a; 两者表达同样的意思:指针a所指向的值不可被修改,但a可以指向其他地址。
const 出现在 * 的右边,表示指针是常量。
例如:int * const a; 指针a不能指向其他地址,但是可以修改a所指向的地址里面的值。
const 出现在 * 的两边,表示指针和被指物都是常量。
例如:const int * const a; 地址和值都不能被改变。
Read it backwards (as driven by Clockwise/Spiral Rule):
int*- pointer to intint const *- pointer to const intint * const- const pointer to intint const * const- const pointer to const int
Now the first const can be on either side of the type so:
const int *==int const *const int * const==int const * const
If you want to go really crazy you can do things like this:
int **- pointer to pointer to intint ** const- a const pointer to a pointer to an intint * const *- a pointer to a const pointer to an intint const **- a pointer to a pointer to a const intint * const * const- a const pointer to a const pointer to an int

浙公网安备 33010602011771号