#include<iostream>
using namespace std;
int main()
{
char p[] = "hello"; //or char p[] = {'h','e','l','l','o',0};
//不能用char *p = "hello"; 否则下一句会出错,hello为字符串常量不能改变
//唯一的一个const赋给非const的特例
//标准的不会造成错用的写法: const char *p = "hello";
//相当于 const char p[] = "hello"; const char p[] = {'h','e','l','l','o',0};
*p = 'j';
cout<<p;
system("pause");
}
















C风格字符串的表示和使用方法
C风格字符串的表示有两种
char *a = "hello!";
char b[] = "hello!";
这两种的效果是一样的,在内存中的表示都是:a代表字符串的起始地址,而字符串以字符串结束标志'/0' 结束,因此实际占的位数比真实位数多一位。在使用时,由于b是const char* 类型的,所以只能使用索引b[i]来访问b中的元素,而企图改变b的指向的操作如b++是不允许的。