Modern C (C11/C17/C23)

nullptr and nullptr_t

/ NULL-pointer /

For decades, C programmers wrote NULL for 'a pointer that points to nothing', but NULL is just a macro that often expands to the integer 0 (or to ((void*)0)). Because it can be a plain integer, NULL sometimes behaves like the number zero in surprising places — for example when passed through a variadic function. C23 introduces nullptr, a dedicated keyword for the null pointer constant with its own type, removing that ambiguity.

nullptr is a predefined constant whose type is nullptr_t (declared in the standard headers). It converts cleanly to any pointer type, comparing equal to a null pointer, but it is NOT an integer, so it cannot be mistaken for the value 0 in a context expecting a number. The practical payoff appears with variadic functions and _Generic: passing nullptr to a function like execl(...) that needs a null pointer terminator is correct in size and type on every platform, whereas passing a bare 0 could pass an int that is narrower than a pointer and corrupt the call. You can also write a parameter or variable of type nullptr_t when you want to accept only the null constant.

It matters as a small but real safety and clarity improvement: nullptr says 'null pointer' unambiguously where NULL might say 'the integer zero'. The honest note: NULL is not going away and still works for ordinary assignments and comparisons; nullptr mainly earns its keep in the corner cases — variadic calls, type-generic code, and overload-like dispatch — where the integer-ness of NULL was the bug.

char *p = nullptr; // typed null pointer, not the integer 0 if (p == nullptr) { /* ... */ } // variadic terminator that is correct in size on every platform: execl("/bin/ls", "ls", nullptr); // bare 0 here could pass a too-narrow int

nullptr has type nullptr_t, not int, so it is the safe terminator for variadic calls where a bare 0 could be the wrong width.

NULL still works for ordinary assignments and tests; nullptr's real value is in variadic calls and type-generic code, where NULL's integer-ness was a latent bug.

Also called
null pointer constanttyped null型別化空指標