When two pointers are subtracted, both must point to elements of the same array object or to one past the last element of the array object (C11, Section 6.5.6 [ISO/IEC 9899:2011]); the result is the difference of the subscripts of the two array elements. Otherwise, the operation results in undefined behavior . (See undefined behavior 48 of Appendix J.) This restriction exists because pointer subtraction in C produces the number of objects between the two pointers, not the number of bytes.
...
CERT C++ Secure Coding Standard: ARR36-CPP. Do not subtract or compare two pointers or iterators that do not refer to the same array or container
ISO/IEC 9899:2011 Section Section 6.5.6, "Additive operators"
...