Table of Contents
Previous Section Next Section

enum

The enum type specifier is used to create enumeration types. An enumeration is simply a list of named integer constants. The general form of an enumeration is shown here:

enum name {name-list} var-list;

The name is the type name of the enumeration. The var-list is optional, and enumeration variables can be declared separately from the type definition. The following code declares an enumeration called color and a variable of that type called c. It then performs an assignment and a conditional test.

enum color {red, green, yellow} c;
 
c = red;
if(c==red) cout << "is red\n";

NOTE: For more information on enumerations refer to “Enumerations” in Chapter 1.


Table of Contents
Previous Section Next Section