`sizeof` — C Keyword

`sizeof` — C Keyword

The sizeof keyword in C: yields the size in bytes of a type or object.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

sizeof (C)

A compile-time operator that yields the size in bytes (as size_t) of a type or expression. The expression is not evaluated.

Syntax

sizeof(type)
sizeof expression

Example

#include <stdio.h>

struct Point { float x, y; };

int main(void) {
    printf("sizeof(char)   = %zu\n", sizeof(char));    /* 1 */
    printf("sizeof(int)    = %zu\n", sizeof(int));     /* usually 4 */
    printf("sizeof(double) = %zu\n", sizeof(double));  /* usually 8 */
    printf("sizeof(Point)  = %zu\n", sizeof(struct Point));  /* usually 8 */

    int arr[10];
    printf("element count  = %zu\n", sizeof arr / sizeof arr[0]);  /* 10 */

    /* Expression is unevaluated */
    int x = 5;
    printf("sizeof(x++)    = %zu\n", sizeof(x++));  /* x is NOT incremented */
    printf("x              = %d\n",  x);            /* 5 */
    return 0;
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}