一、Bjarne在他的C++書中講遇到*請念“pointer to”,然后按此法把一個聲明從右往左讀。比如:
char ** p1;
//? ? p1 is a (pointer to pointer to char)
const char **p2;
//? ? p2 is a (pointer to pointer to const char),說明**p2 不能更改,也可以直接看const 修飾的是char類型和**p2變量;
char * const * p3;
//? ? p3 is a (pointer to const pointer to char),說明*p3不能更改,也可以直接看const修飾的是 *p3;
const char * const * p4;
//? ? p4 is a (pointer to const pointer to const char),說明*p4和**p4都不能更改,也可以直接看const修飾誰,有兩處,第一處const修飾的是char類型的 * const * p4變量,化簡就是const修飾的是**p4,第二處const修飾的是*p4,說明*p4和**p4都不能更改。
char ** const p5;
// p5 is a (const pointer to pointer to char),說明p5本身不能更改,也可以直接查看const修飾的是p5。
const char ** const p6;
// p6 is a (const pointer to pointer to const char),說明p6和**p6不能更改,也可以直接查看const修飾的是p6和**p6
char * const * const p7;
// p7 is a (const pointer to const pointer to char),說明p7和*p7不能更改,也可以直接查看const修飾的是p7和*p7
const char * const * const p8;
// p8 is a (const pointer to const pointer to const char),說明p8和*p8和**p8都不能更改,也可以直接查看const修飾的是p8和*p8和**p8