Since &chr gives char* (implicit addition of const here), and cout assumes that it is a string and therefore is null-terminated, which is not the case.
However, &chrS gives char(*)[] , which will not decay to const char* and therefore will be output via operator<<(std::ostream&, const void*) overload operator<<(std::ostream&, const void*) , which prints the address.
If you need this behavior for const char* , you will need to do an explicit cast. The fact that there is no difference between a C string and a single character pointer is one of the main drawbacks of C strings.
source share