我们可以从三段代码理解两者
1.
// 均包含结束标识符'\0'
char test1[] = "yes!";
char* test2 = "yes!";
cout<<test1<<endl; // yes!
cout<<test2<<endl; // yes!
cout<<sizeof(test1)<<endl; // 输出为5即字符串的长度
cout<<sizeof(test2)<<endl; // 输出为8即指针变量的长度
2.
test2是一个指针变量,所以能被test1赋值。反之则不行。
char test1[] = "yes!";
char* test2 = test1;
test2[3] = '?'
cout<<test2<<endl; // yes?
3.
char test1[] = "yes!"
char* test2 = "yes!"
test1[3] = '?'
cout<<test1<<endl; // yes?
test2[3] = '?' // error 因为test2指向的是字符串常量,内容不能被修改