You can't just cout
an array. Arrays are not cout
-able. Whenever you successfully cout
something of type T
, it means that there's a dedicated overloaded <<
operator designed specifically to cout
values of type T
. And there's no dedicated <<
operator for cout
-ing arrays (aside from strings). For this reason the compiler chooses the closest match for the given argument type: a <<
operator for pointers. Since arrays are convertible to pointers, that <<
is applicable here.
If you want to cout
the values of all elements of your array, you'll have to either cout
them manually, one by one, or use some standard algorithm that can do it for you. For example
std::copy(array, array + 9, std::ostream_iterator<int>(std::cout, " "));