NULL not type safe. For historical reasons, it was defined as 0 without casting, and a warning of silence of the compiler about the number of castes for the pointer at this special zero.
In an instant you can do:
void* p = 0;
but not this without implicit casting:
void* p = 1234;
a side effect is that it can be abused as numerical values, as mentioned in another answer.
nullptr improve this by using a pointer, you cannot assign this integer. Because the behavior is changed, a new name is created for backward compatibility.
Also note that nullptr processed by the compiler, its actual value is not displayed to the user (for example, zero in case of NULL ). It is much easier to have an architecture-dependent value, say 0xdeadbeef , without changing the logic of the programmer's code.
Non-maskable Interrupt Aug 31 '15 at 1:06 2015-08-31 01:06
source share