&pm[0]
is the same as &(*(pm+0))
which is the same as &(*pm)
which is the same as pm
. And pm
points to the first element of the zero-terminated character array message
.
Now, the <<
operator for the output stream, when passed a char*
or const char*
treats that as a pointer to a null-terminated array of characters. That is, a C string.
So, the entire contents of the string are output to the output stream.
&
should output the address of pm[0]
No, the &
operator is not related to the output. The &
operator is part of the expression &pm[0]
. This expression is evaluated, as described above. And the result of that evaluation is passed to the best matching overload of the output stream's <<
operator. It is the <<
operator that determines how the value of your expression is output, and that determination is based on the type of your expression.
In order to output an address, you would need to supply an argument of a different type, for instance void*
. You can cast the char*
pointer like this:
static_cast<const void*>(&pm[0])