Why do we have nullptr but not nullchar?

No, because there’s not as much reason to, really. nullptr was added to remove the need of the NULL macro, which in C is defined as something like (void*)0. In C, void* is implicitly convertible to any pointer type, so this would work. However, this is not true in C++, which removed this implicit convertibility (but not its inverse, from any pointer type to void*), to increase type safety. However, C++ still wanted to have an easy way to make any pointer a null pointer, which is why nullptr_t was introduced, which is implicitly convertible to any pointer type like void* once was, BUT can only contain the null pointer value, nullptr. In C++ you can represent a null character with '\0' with no type ambiguity or unnecessary explicit conversions, so there’s no reason for a nullchar value, which would also take up another valuable reserved identifier (standard committee really likes to preserve those.)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top