Enumerations and Typedef

Lesson 19 of 20

Turn magic numbers into readable names with enum, then give every type a tidy nickname with typedef.

The big picture

Names for numbers, nicknames for types

Two small features that make C readable: enum gives numbers names, typedef gives types nicknames.

Named numbers

An enum gives small integer constants readable names — RED is really 0.

Auto-numbering

Members count up from 0 automatically unless you assign a value yourself.

typedef = nickname

typedef creates an alias so you can write Count instead of unsigned long long.

Better together

typedef enum turns enum TrafficLight into just TrafficLight in declarations.