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