Question

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!

Was it helpful?

Solution

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;

OTHER TIPS

Use that:

char* array = 'trololo';
int addr = &array;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top