Why on earth do you thing that would work? Most of the time, it
won't. If your array contains 0, it obviously won't, and if
your array doesn't contain 0, it's very likely to continue too
far (resulting in undefined behavior).
To traverse the array:
for ( int n: array ) {
std::cout << n << std::endl;
}
Or in pre-C++11:
for ( int* current = begin( array ); current != end( array); ++ current ) {
std::cout << *current << std::endl;
}
In C++11, you can also do this, and you don't even have to
write your own versions of begin and end. Pre C++11, you'll
need:
template <typename T, size_t n>
T*
begin( T (&array)[n] )
{
return array;
}
template <typename T, size_t n>
T*
end( T (&array)[n] )
{
return array + n;
}
Put them in some universally included header.