Enumeration declaration

Enumerations:

  • Are unique integer data types
  • May only contain a specified list of values
  • Values are specified as symbolic constants

Syntax

enum typeName { label0, label1, ..., labeln }

The compiler sets label0 = 0, label1 = 1, labeln = n.

Code example

enum month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC};

You can assign a specific value to any label.
Subsequent labels will increment from that value.

Code example

enum group {Peter, Paul = 5, Mary};
// label values: Peter = 0, Paul = 5, Mary = 6