//字符串常量在常量存储区,不允许修改值,程序结束后由系统释放
//str 存放的是字符串常量的首地址
const char* str = "hello";
cout << "=" << str << endl; //c++重载了<<,支持const char*显示字符串
printf("a address: %p\n", str); // 打印地址
cout << "=" << *str << endl; //h
cout << "=" << *(str+1) << endl; //e
cout << "=" << sizeof("hello") << endl; //6
cout << "address=" << &("hello") << endl; //获得字符常量的地址
cout << "address=" << (void*)("hello") << endl; //获得字符常量的地址
//字符串常量实际上是一个指针常量
//这个表达式计算“指针值 + 1”的值
// cout << "=" << "hello"+1 << endl; //ello
printf("%p\n", "hello" + 1);
cout << "=" << *("hello" + 1) << endl; //e
cout << "=" << "hello"[1] << endl; //e
cout << "--------------------" << endl;
//数组变量,存在栈区
char as[]="hello";
cout << "=" << as << endl; //hello //c++重载了<<,支持const char*显示字符串
printf("a address: %p\n", &a); // 打印a的变量地址
as[0] = 'r';
cout << "=" << as << endl; //hello