ptrdiff_t(3type)

πŸ’– ptrdiff_t(3type) β€” the whole vibe πŸ’–

okay bestie, welcome to <ptrdiff_t>'s page, it lives in section 3type (that's the "here's a typedef, let me explain it" section, iykyk) and honestly? it's giving essential.

✨ NAME ✨

ptrdiff_t β€” count of elements or array index


πŸ“š LIBRARY πŸ“š

Standard C library (libc) 🫢


🌸 SYNOPSIS 🌸

#include <stddef.h>

typedef /* ... */  ptrdiff_t;

like. that's it. that's the whole declaration. typedef /* ... */ bestie, the real guts are up to your implementation πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

So what IS this queen? <pink>Used for a count of elements, or an array index.</pink> That's her whole job description πŸ’…

She's also <cyan>the result of subtracting two pointers</cyan> β€” like, literally, subtract one pointer from another and boom, you get a ptrdiff_t (the name is not subtle, it's giving "pointer difference").

And the important part, no cap: <hotpink>it is a signed integer type capable of storing values in the range [PTRDIFF_MIN, PTRDIFF_MAX]</hotpink>. SIGNED. Which means she can go negative. Which means your pointer math can go negative. Which is exactly why she exists and why size_t can't do her job πŸ‘‘

✨ the printf/scanf tea ✨

The length modifier for ptrdiff_t for the printf(3) and the scanf(3) families of functions is t, resulting commonly in %td or %ti for printing ptrdiff_t values. So next time you're printing one, don't be out here using %d like a menace β€” use %td or %ti πŸŽ€


πŸ‘‘ STANDARDS πŸ‘‘

C11, POSIX.1-2024.


🌈 HISTORY 🌈

C89, SUSv1, POSIX.1-2001.

she's been iconic since forever, fr fr πŸ’€βœ¨


πŸŽ€ SEE ALSO πŸŽ€


lowkey the cutest little typedef in <stddef.h>, tbh πŸ¦‹

this page came to you courtesy of Linux man-pages 6.20, dated 2026-02-08 πŸ’– stay signed, bestie, and may all your pointer differences fit in range 🫢⭐

πŸ“¦ 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