This is because pointers do not behave like integers. This behavior is undefined because the standard talks about it.
However, on most platforms (if not all), you will not be able to crash or run into questionable behavior if you do not find the array. But then, if you do not play it, what's the point of making an addition?
However, note that the expression following one end of the array is technically 100% “correct” and guaranteed to not fail in §5.7 ¶5 of the C ++ 11 specification. However, the result of this expression is not specified (it simply will not guarantee overflow) ; while any other expression that goes more than one beyond the bounds of the array is explicitly undefined.
Note. This does not mean that it is safe to read and write due to bias. You will probably be editing data that does not belong to this array and will cause state / memory corruption. You simply will not throw an overflow exception.
I guess this is because it is not only acting out this wrong. Also pointer arithmetic, pointer comparison, etc. So just say don't do it , and not list situations where it can be dangerous.
Luchian Grigore May 6 '12 at 19:34 2012-05-06 19:34
source share