Dereferencing the return value of std::vector::end()
is cause for undefined behavior. There is no point trying to make sense of what happens if you do.
From http://en.cppreference.com/w/cpp/container/vector/end:
This element acts as a placeholder; attempting to access it results in undefined behavior.
Re. the second part, the only thing I could find in the C++11 standard is:
5.3.1 Unary operators
1 The unary *
operator performs indirection: the expression to which it is applied shall be a pointer to an object type, or a pointer to a function type and the result is an lvalue referring to the object or function to which the expression points. If the type of the expression is “pointer to T
,” the type of the result is “T
.” [ Note: a pointer to an incomplete type (other than cv void
) can be dereferenced. The lvalue thus obtained can be used in limited ways (to initialize a reference, for example); this lvalue must not be converted to a
prvalue, see 4.1. — end note ]
The result of dereferencing a NULL pointer seems to be unspecified.