Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

nullptr_t — the type of nullptr

In C23, nullptr_t from <stddef.h> names the type of nullptr, distinct from pointer and arithmetic types.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stddef.h>
nullptr_t name = nullptr;

nullptr_t is a type name provided by <stddef.h> in C23. It is a complete scalar type with one value: nullptr. In C23 source code, nullptr is a keyword that denotes a predefined constant, not a type name.

A nullptr_t value converts to a pointer type as a null pointer, or to bool as false. It is neither a pointer nor an arithmetic type; it cannot store object addresses.

NULL is a macro with an implementation-defined definition, so do not assume its type is nullptr_t. The example requires C23 support.

Examples

#include <stddef.h>
#include <stdio.h>

int main(void)
{
    nullptr_t n = nullptr;
    int *p = n;
    printf("%d %d\n", p == nullptr, (bool)n);
    return 0;
}

Result

1 0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources