Enumerated Data Types

Uday:- ( ubikkasa@uncc.edu )


An Enumerated data type can be termed as a set of constants with unique names.

The set of constants are called enumerators and they behave like integers. Enumerators start with a value of 0 and increase by 1 unless and until some other value is explicitly specified.

Example: enum Days{sunday, monday, tuesday, wednesday, thursday, friday,saturday}.
Here sunday=0, monday=1, .... saturday=6.

The enumerators can also be assigned a value explicitly.

enum Days{sunday=10, monday.... saturday}
and the values for the rest of the enumerators are assigned by incrementing the value of the previous element by 1, i.e.,
monday=11.... saturday=16

They can also be assigned any random values i.e., values which are not in any particular order.
enum money{penny=1, nickel=5, dime=10, quarter=25}

Here is a simple example using the enumerated data types.

Note : The enumerators do not need to have unique values,i.e. two or more enumerators can have the same value but the names should be unique.