countof(3)

countof3

Count the number of elements in an array

Usage

#include <stdcountof.h>

size_t countof(array);

Library

Standard C library (libc)

Overview

This operator counts the number of elements in an array.

If the operand is not an array, it produces a compilation error.

There's a keyword, _Countof(), that behaves identically, and can be used without including <stdcountof.h>.

Return value

The number of elements in the array.

Standards

C2y.

History

gcc 16, clang 21, gnulib 202507.

From man-pages 6.19-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.