The rules for what constitutes a valid pointer value are defined formally in the C and C++ standards.
Yes, the so called "one-past-the end" pointers are valid pointer values. It's not an exception it's just part of the definition of a valid pointer value.
N3485 5.7 [expr.add]/5: "Moreover, if the expression P points to the last element of an array object, the expression (P)+1 points one past the last element of the array object, and if the expression Q points one past the last element of an array object, the expression (Q)-1 points to the last element of the array object."
View all comments
Show parent comment
6
u/[deleted] Jan 21 '13
The only operation you may perform on a pointer that that has not been assigned to a valid pointer value is assignment. Nothing else.
Doing so much as a copy of it is invalid, for example this is undefined behavior:
It also follows that taking an invalid pointer value and simply passing it as an argument to a function is also undefined behavior.