`typedef` — C Keyword

`typedef` — C Keyword

The typedef keyword in C: creates a type alias.

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.

typedef (C)

Creates an alias for a type, making complex type declarations more readable.

Syntax

typedef existing-type alias-name;
typedef return-type (*func-alias)(params);

Example

#include <stdio.h>

typedef unsigned long ulong;
typedef int (*BinaryOp)(int, int);

/* Common C pattern: typedef + struct in one declaration */
typedef struct {
    double x;
    double y;
} Point;

int add(int a, int b) { return a + b; }

int main(void) {
    ulong n = 1000000UL;
    printf("%lu\n", n);

    BinaryOp op = add;
    printf("%d\n", op(3, 4));   /* 7 */

    Point p = {1.0, 2.0};
    printf("%.1f %.1f\n", p.x, p.y);
    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;
}