不同之处在于,const char *
是指向const char
的指针,而char * const
是指向char
的常量指针.
首先,所指向的值不能更改,但指针可以更改.第二,所指向的值可以改变,但指针不能改变(类似于引用).
还有一个
const char * const
它是指向常量字符的常量指针(因此关于它的任何内容都不能更改).
注:
以下两种形式是等效的:
const char *
和
char const *
The exact reason for this is described in the C++ st和ard, but it's important to note 和 avoid the confusion. I know several coding st和ards that prefer:
char const
结束
const char
(带或不带指针)以便const
元素的位置与指针const
的位置相同.