Reading or writing through a null pointer
suggest changeint *ptr = nullptr;
*ptr = 1; // Undefined behavior
This is undefined behavior, because a null pointer does not point to any valid object, so there is no object at *ptr
to write to.
Although this most often causes a segmentation fault, it is undefined and anything can happen.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents