This is a good example of why you should not mark your questions in both C and C ++:
For C, this is covered by the standard.
6.5.9 Equality Operators
6 Two pointers compare the same if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at the beginning) or a function, both are pointers to the same past, the last element of the same object array , or one is a pointer to one end of the end of one array object, and the other is a pointer to the beginning of another array object, which occurs immediately after the first array object in the address space.
For C ++, this is not so clear:
5.10 Equality Operators [expr.eq]
1 == (equal) and != (Not equal) operators have the same semantic restrictions, transformations, and result type as relational operators, except for their lower priority and true result. [Note: a<b == c<d is true when a<b and c<d have the same truth value. - end note] Pointers of the same type (after pointer conversions) can be compared for equality. Two pointers of the same type are compared equally if and only if both are equal to zero, both indicate the same function, or both represent the same address (3.9.2) .
Technically, I donβt see where the standard requires that two pointers of the past end represent the same address. I can find where the standard requires the object to have an address, and the & operator returns that specific address (so that with a double address address the same pointer value is obtained), but the past end pointer does not point to the object, so this does not apply . They can be different, while subtraction works to return to the same array base.
In practice, however, you will not have to worry about this, and it will work in C ++ in the same way as in C.
Update: to JohnB's answer and comments there, the C ++ standard may have required this much more explicitly, but it does require indirectly nonetheless.