【发布时间】:2020-10-08 07:14:17
【问题描述】:
因为它可以用于整数和数值数据 当一个指针被创建并像这样显示时
int number = 5;
int *numberaddress = &number;
cout << "The number is "<< *numberaddress << endl;
cout << "The address of number is "<< numberaddress << endl;
但是,当对字符串或常量字符串指针执行相同操作时,它会给出字符串本身,如下所示
char string[20] = "string";
char *stringaddress = string;
const char *stringcopy = "string";
cout << "The string is " << stringaddress << endl;
cout << "The address of string is " << *stringaddress << endl;
cout << "The stringcopy is " << stringcopy << endl;
我怎样才能通过指针而不只是字符串来获取字符串的地址,有没有办法或者有不同的方法呢?
【问题讨论】:
-
很确定这是一个骗子。基本上是
std::cout << (void*)stringaddress。 -
这能回答你的问题吗? Why is address of char data not displayed?
-
void* 在这里做什么...?我是 C++ 新手,请..