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.
and NULL - NULL? undefined behavior according to ISO C 😭 β€” but it's defined to be 0 in 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