I am a little confused here. In the statement const char *str="Hello";
, str
is a pointer to a char
variable pointing to the first character 'H'
of the string "Hello"
, so str
should contain the address of the 'H'
character. And yet, if I use cout<<str
, it prints the entire string "Hello"
and not the address.
And also, If I use cout<<*str
to print the value stored in the address pointed to by str
, it prints the char 'H'
correctly.
Can someone please explain how and why this happens? This may be very basic, but an explanation would help me understand these concepts more clearly.