int *i = new int(1);
cout << i << endl;
Run Code Online (Sandbox Code Playgroud)
将打印整数的地址.
char *c="cstring";
cout << c << endl;
cout << &(*c) << endl;
Run Code Online (Sandbox Code Playgroud)
两者都会打印"cstring".我想这个行为可以简单地通过ostream& operator<< (ostream& out, const char* s );IOstream库中的实现来解释.
但是,如果你真的想要打印数据c的地址怎么办呢?