因为char*变量默认是字符串的地址,所以
#include <iostream>
int main()
{
char ch = 'a';
// std::string s = "324";
// std::cout << s << std::endl;
char* ptr_ch = &ch;
std::cout << "ptr_ch: " <<ptr_ch << std::endl;
std::cout << "*ptr_ch: " << *ptr_ch << std::endl;
return 0;
}
执行结果
ptr_ch: aG
*ptr_ch: a
ptr_ch的值不是地址,而是一个奇怪的东西,但如果将注释的两行代码解开来,ptr_ch的值就为*ptr_ch的值了
执行结果
324
ptr_ch: a
*ptr_ch: a
编译器为eclipse