The macro NULL
is an implementation-defined null pointer constant, which may be.
0
void*
| (since C23) |
A null pointer constant may be converted to any pointer type; such conversion results in the null pointer value of that type.
#include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <inttypes.h> int main(void) { // any kind of pointer can be set to NULL int* p = NULL; struct S *s = NULL; void(*f)(int, double) = NULL; printf("%p %p %p\n", (void*)p, (void*)s, (void*)(long)f); // many pointer-returning functions use null pointers to indicate error char *ptr = malloc(0xFULL); if (ptr == NULL) printf("Out of memory"); else printf("ptr = %#" PRIxPTR"\n", (uintptr_t)ptr); free(ptr); }
Possible output:
(C23) | the type of the predefined null pointer constant nullptr (typedef) |
C++ documentation for NULL |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/c/types/NULL