What you have is an array of chars.
name[0]
will return the first char, and
&name[0]
will return a pointer (the memory address) to that char (a
char*
), as you expect.
What's happening though, is that
cout
is interpreting that
char*
as a string and printing out the characters instead of the address.
The trick you found using
static_cast
is close, but it's missing a crucial part - the type to cast to, the aim is to cast the
char*
to a
void*
so that
cout
won't treat it as a string.
char name[] = "Hello";
cout<<"the memory address of name[0] is:"<<static_cast<void*>(&name[0])<<endl;
For more info on different types of casts (as
static_cast
is not the only one) see
http://www.cplusplus.com/doc/tutorial/typecasting/[
^]