在C++(代码块)中显示数组地址

Show array address in C++ (Code Blocks)

本文关键字:显示 数组 组地址 C++ 代码      更新时间:2023-10-16

我是C++的新手,我想使用Code::Blocks功能Watches 显示数组的地址

我想检查的线路代码是这个char hello[7] = "hello";

当我启动Debug并打开Watches窗口时,它只显示"hello0000"

如果我尝试其他类似char *hi = "hi";的东西,Watches窗口会显示

0x46e024 <_ZSt16__convert_from_vRKPiPciPKcz+4644900> "hi",正如您所看到的,它显示地址和值。

如何使用hello进行同样的操作?我的意思是显示它的地址?

谢谢!

您的问题是调试器过于智能,无法自动解释地址。地址已经是hello的值。没有必要像其他答案所建议的那样,使用&来获取该变量的地址。

您可能会使用另一个明确为指针的变量,为其分配hello,并在调试器中查找该值:

char hello[7] = "hello";
char* helloaddr = hello;

使用:

char* array = 'trololo';
int addr = &array;