Is this valid C++?
int main()
{
int i = 0;
int* pi = &i;
++pi;
}
I know that one-past-end pointers are allowed for array types, but I'm not sure in this case. Does that code technically have undefined behavior?
Is this valid C++?
int main()
{
int i = 0;
int* pi = &i;
++pi;
}
I know that one-past-end pointers are allowed for array types, but I'm not sure in this case. Does that code technically have undefined behavior?
Yes, it is okay. It is one of the four categories of values any pointer type may hold.
As you can see, array types are also mentioned here, with their hypothetical object past the end. And as the footnote in [expr.add] explains, the arithmetic to obtain a one-past-the-end pointer is meant to be valid too: