← Structs and UnionsC PROGRAMMING 1.4.D

typedef

Naming struct/pointer types cleanly.

StatusCollected
NotesChapter test: 4/5

One idea: giving a type a cleaner name so it doesn't have to be spelled out in full every time.

typedef struct point {
    int x;
    int y;
} Point;

Point p1 = {1, 2};        /* instead of: struct point p1 = {1, 2}; */

typedef struct point *PointPtr;
PointPtr pp = &p1;

Without typedef, every declaration needs the struct keyword — struct point p1;, not just point p1;. It's a naming convenience only, not a new type — Point and struct point are the exact same thing to the compiler.

Notes from readers

Comments — via GitHub