basic_ostream
's operator<<(basic_ostream<>&, const char*)
function requires that the char*
is non-null - it is designed to print the string the pointer points to. So it is undefined behavior to send a null char*
to cout
. (See C++11 27.7.3.6.4/3 "Character inserter function templates").
However, basic_ostream
's operator<<(basic_ostream<>&, const void*)
function simply prints the value of the pointer, so a null pointer will work properly with that overload.