C/C++ Arena

Step 5 of 6

enum

An enum gives names to a set of integer constants, which makes code self-explanatory:

enum Side { T, CT };            // T = 0, CT = 1
enum Side s = CT;

Enums pair perfectly with switch.

Your turn: write const char *weapon_name(enum Weapon w) that returns "rifle", "pistol", "knife" for the three enum values and "?" otherwise.

Previous: Arrays of structs Next: typedef