NULL(3const)
π NULL(3const) π
okay so bestie. today we're talking about NULL, from the <stddef.h> corner of the Standard C library (that's libc, mwah π). this is a section 3const page, which is man-speak for "it's a constant, not a function, don't @ me". she's a legend. she's been here since before any of us were born. let's get into it π«Ά
β¨ NAME β¨
NULL β the null pointer constant π³οΈβ¨
π LIBRARY π
Your one and only Standard C library, aka libc. the blueprint. the originator. π
π¦ SYNOPSIS π¦
#include <stddef.h>
#define NULL ((void *) 0)
that's it. that's the whole thing. one macro, infinite power. π
πΈ DESCRIPTION πΈ
NULL is a null pointer constant, which is a fancy way of saying: it's a pointer that literally does not point at anything. it's pointing into the void. it's at the function but nobody's home. π«₯
not "points at zero bytes", not "points at nothingness the place" β it just isn't pointing. periodt. π
β STANDARDS β
- C11 π
- POSIX.1-2024 π
both said yes, both put a ring on it. π
π HISTORY π
- C89 π±
- POSIX.1-1988 π±
so she's been famous since the 80s. vintage. iconic. genuinely older than your parents' playlist. π
π NOTES π
NULL isn't gatekeeping, okay? she hangs out in so many headers besides <stddef.h>. these ones all provide her too:
<locale.h><stdio.h><stdlib.h><string.h><time.h><unistd.h><wchar.h>
so if your code includes any of those and suddenly NULL just... works? yeah. that's why. iykyk π§
π CAVEATS π
okay bestie, this is the part where we sit down and have a serious little chat. β
dereferencing a null pointer is undefined behavior, and in practice that usually means a segmentation fault. so like. don't. obviously.
it's also undefined behavior to do pointer arithmetic on it. so NULL + 1? that's not cute. that's not a vibe. that's UB.
andNULL - NULL? undefined behavior according to ISO C π β but it's defined to be0in C++. yes, the two languages have beef about this. classic.
to avoid confusing the poor humans who have to read your code later (hi, it's me, i'm the human π), don't compare pointer variables to 0, and don't assign 0 to them either. just always use NULL. literally always. no cap. π
and please β do not confuse NULL with NUL. different girl completely. NUL is the ascii(7) character, and in C she's written as '\0'. NULL is a pointer. NUL is a character. they are not the same. they are not sister cities. they are not even mutuals. πΈ
π BUGS π
okay so say you need to set a pointer variable to a null pointer. would you reach for memset(3) to zero it out? (this is usually what people do when they're zeroing a whole struct that happens to contain pointers. very common. very understandable. very π©.)
don't. because ISO C and POSIX do not guarantee that a bit pattern of all 0s represents a null pointer. like. it might. it might not. it's giving gambling. π
want an example program that does this correctly? go look at the EXAMPLES section in getaddrinfo(3). go. now. π₯
π SEE ALSO π
that's the whole page, bestie!! ππ if you take nothing else from this: use NULL, never deref it, and do not let anyone tell you NUL is the same girl. π
β¨
this page came to you from Linux man-pages 6.20, dated 2026-01-05 β and the entry itself is NULL(3const). mwah, ily, go write some safe code. π«ΆπΈπ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms