typestar

typedef in C

Giving types shorter, clearer names.

typedef struct {
    char name[32];
    int score;
} Player;

typedef unsigned long ScoreID;

Player promote(Player p, int bonus) {
    p.score += bonus;
    return p;
}

How it works

  1. An anonymous struct plus typedef names it Player.
  2. typedef also aliases a plain type like unsigned long.
  3. The alias reads like any other type.

Keywords and builtins used here

The run, in numbers

Lines
11
Characters to type
153
Tokens
41
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 26 seconds.

Type this snippet

Step 3 of 3 in Structs, step 21 of 25 in Pointers & memory.

← Previous Next →