pointer does not give memory address

I got through the tutorial of cplusplus.com on pointers with inserting the code:

char a;
char *b;
char **c;
a='d';
b=&a;
c=&b;

Then I wanted to print the memory addresses:

cout<<b<< endl;
cout<<c<< endl;

The terminal answered:

dP?
0xbffe4fd4

I would expect two hex numbers, but the first seems to be something different.
How can I get the memory address of char a ?
thank you
Tom
Well, when you feed a char* to std::cout, it thinks it should print a C string.

1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    const char *cp = "Hello, World!";

    std::clog << cp << '\n'; // what should this print?
    std::clog << static_cast<const void *> (cp) << '\n';
}
Hello, World!
0x48f064


Traditionally... that means, back in the good old C whence C++ originated... char[] (char arrays) were used as text strings. And arrays decay to pointers. So printing a char* is a special case.

You can get around this as shown above, by using a cast.
Last edited on
Topic archived. No new replies allowed.