#include <iostream>
using namespace std;
/**
* 字符串变量
*
* 字符串常量
*
* 数组变量的值是不允许改变的
*
* 字符串的指针表示方法
* 指针表示方法:
* char* pStrHelloWorld = "helloworld";
*
* char[] 和 char*的区别:
* 地址和地址存储的信息
* 可变与不可变
*
* 如:
* char strHelloWorld[11] = {"helloworld"};
* strHelloworld不可变(就是将strHelloworld指向其他变量)
* strHelloworld[index]的值可变
*
* char* pStrHelloWorld = "helloworld";
* pStrHelloworld可变,但是pStrHelloWorld[index]的值可变不可变取决于
* 所指向存储区是否可变。
*/
int main(int argc, char const *argv[])
{
/* code */
char strHelloWorld[12] = {"helloworld"};
char strhelloWordl2[] = {"helloworld"};
char c1 = 0;
char c2 = '\0';
char c3 = '0';
cout<<strHelloWorld<<endl;
cout<<strhelloWordl2<<endl;
// 字符串的指针表示方法 "hellworld"是字符串常量
// strHelloWorld 是字符串变量
char* pStrHelloWorld = "helloworld";
cout<<pStrHelloWorld<<endl;
// 字符数组和字符串指针
for (int i = 0; i < 10; i++)
{
/* code */
strHelloWorld[i]+=1;
cout<<strHelloWorld[i]<<endl;
}
for (int i = 0; i < 10; i++)
{
/* code */
// pStrHelloWorld[i]+=1;
// cout<<pStrHelloWorld[i]<<endl;
cout<<*(pStrHelloWorld+i)<<endl;
}
return 0;
}
输出如下:
helloworld
helloworld
helloworld
i
f
m
m
p
x
p
s
m
e
h
e
l
l
o
w
o
r
l
d