The only suitable overload of operator<<
is that for bool
, so the array is converted (via a pointer) to bool
, giving true
since its address is non-null. This outputs as 1
unless you use the std::boolalpha
manipulator.
It can't use the overload for const char *
which would output the string, or that for const void *
which would output the pointer value, since those conversions would require removing the volatile
qualifier. Implicit pointer conversions can add qualifiers, but can't remove them.
To output the string, you'd have to cast away the qualifier:
std::cout << const_cast<const char*>(test) << "\n";
but beware that this gives undefined behaviour since the array will be accessed as if it were not volatile.
printf
is an old-school variadic function, giving no type safety. The %s
specifier makes it interpret the argument as const char *
, whatever it actually is.