const char*
来源:互联网 发布:视频格式无损转换软件 编辑:程序博客网 时间:2024/05/13 12:52
char const* p2="Mary";
p2 is a pointer to a constant "Mary"
p2 can change to point to another constant string, but you can't change the value "May" thru p2.
p1 is a constant pointer to "John"
p1 can't change, but you can change "John" thru p1.
1
2
3
4
5
6
7
2
3
4
5
6
7
char const* p2 = "Mary";*p2 = 'C'; // not allowed.p2 = "Margareth"; // allowedchar * const p1 = "John";*p1 = 'C'; // allowedp1 = "Margarth"; // not allowed