摘抄几段Dan Saks对const的讲解:
typedef void * VP;
Type specifiers contribute to the type of the declarator-id; other specifiers provide nontype information that applies directly to the declarator-id.
The order in which the declaration specifiers appear in a declaration doesn't matter. Thus, for example,
const VP vectorTable[]
is equivalent to:
VP const vectorTable[]
and
const void *vectorTable[]
is equivalent to:
void const *vectorTable[]
The only declaration specifiers that can also appear in declarators are const and volatile.
For example, the const in:
void *const vectorTable[]
The order of the declaration specifiers doesn’t matter to the compiler. Therefore, these declarations are equivalent:
const void *vectorTable[]
void const *vectorTable[]
于是下面的声明就好理解了。
const int * p; //表示p所指向的内容为只读
int const * p; //同上
int * const p; //表示p为只读
const int * const p; //表示p及其指向的内容都为只读
int const * const p; //同上
char * const * (*next)(); //表示next是一个指向函数的指针,函数的返回值为指向char类型只读指针的指针。