I'm new at C++ and I'd like to show an array's address using the Code::Blocks feature Watches

The line code I want to check is this char hello[7] = "hello";

When I launch Debug and I open the Watches window, it only shows "hello\000\000".

If I try somthing else like char *hi = "hi";, the Watches window shows

0x46e024 <_ZSt16__convert_from_vRKPiPciPKcz+4644900> "hi" so as you see, it shows the address as well as the value.

How can I do the same with hello ? I mean showing its address?

Thanks!

有帮助吗?

解决方案

You problem is that the debugger is too intelligent and automatically interprets the address. The address is already the value of hello. There is no need to take the address of that variable with & as the other answers suggest.

Would you could probably do is use another variable that is explictly a pointer, assign hello to that and look up that value in the debugger:

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

其他提示

Use that:

char* array = 'trololo';
int addr = &array;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top