On this page
  1. sizeof
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

sizeof

Prev: builtins | Up: builtins | Next: _Alignof
Rel: size_t, Arrays & C Strings
Ref: cppreference — sizeof
Tags: #public #prog #c #builtins #tier/core


Availability

Built-in (Operator) — requires no #include header.

Syntax & Overview

sizeof(type)  |  sizeof expr

Compile-time operator (runtime only for VLAs) returning the size in bytes of a type or expression as size_t.

Notes & Pitfalls

Example

#include <assert.h>
#include <stddef.h>

int main(void) {
    int arr[5] = {1, 2, 3, 4, 5};
    size_t count = sizeof(arr) / sizeof(arr[0]);
    assert(count == 5);
}

Linked from

Related notes