Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous
Next: Arrays Up: C++ Summary Previous: Text input and output

Enumerated types

When a small set of values is needed to represent a non-numeric quantity, an enumerated type can be declared, e.g.:

   enum Days {Mon, Tue, Wed, Thu, Fri, Sat, Sun};
   Days today = Tue;
creates a new variable type with legal values Mon, Tue, Wed, Thu, Fri, Sat, Sun. Variable today is initially assigned the value Tue, and the compiler will ensure that only values in the range Mon to Sun may be assigned to today.
© Cambridge University Engineering Dept
Information provided by Tim Love
2006-12-08