在Effective C++里面,说到尽可能使用const等来替代宏#define,其中提到了指针的const,应该是这种形式:
const char * const authorName = "light"
这样子,*authorName 与 authorName 都是const,都不允许改变。
如果是:
const char * authorName = "light"
同理,如果是:
char * const authorName = "light"
则*authorName 允许改变,但 authorName 不允许改变。
这里可以这么认为,*号是与后面的变量相连的,不是与前面的类型相连。
所以,像是这样的定义:int * p1, p2; 那么p1是指针,但p2是int类型。
百度百科的说明,还是很详细的。可以查阅。