in practice, it just sets ptr to some value
In theory, a pointer that indicates somewhere invalid is simply not indicated.
Pointers are not integers: this is something that points to other things or to invalidation.
You cannot just set them to any number you like.
in this example, there is nothing but assignment and then qualified dereferrencing - the value is used only if it is confirmed, the question arises, why is the parameter value a problem?
Yes, you must be very unlucky to face the practical consequences of this. “Undefined behavior” does not mean “always crashing”. Why should a standard impose semantics for such an operation? What do you think should be such semantics?
source share