enum Keyword

Keyword Index

Defines a set of constants of type int.

The syntax for defining constants using enum is

enum [tag] {name [=value], ...};
The set can optionally be given a type tag name with tag. name is the name of a constant that can optionally be assigned the (constant) value of value, etc. For example,
enum Numbers {One = 1, Two = 2, Three = 3, Four = 4, Five = 5};
If value is missing, then a value is assumed to be the value of the previous constant in the list + 1. If this is the first constant in the list, the default value is 0.

If you give a type tag name, then you can declare variables of enumerated type using
enum tag variable-names;
For example,
enum Numbers x, y, z;
declares three variables x, y and z, all of type Numbers (they are, in fact, integer variables). More precise, 'enum tag' becomes a new type which is equal in rights with any built-in type.