这个:
const char * terry = "hello";
cout<<terry;
Run Code Online (Sandbox Code Playgroud)
打印hello而不是的内存地址'h'.为什么会这样?
当我运行以下代码时:
int i[] = {1,2,3};
int* pointer = i;
cout << i << endl;
char c[] = {'a','b','c','\0'};
char* ptr = c;
cout << ptr << endl;
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
0x28ff1c
abc
Run Code Online (Sandbox Code Playgroud)
为什么int指针返回地址,而char指针返回数组的实际内容?