What are Enumerations in C++ and Object Oriented Programming ? Explain with an example ?

 
 

An enumeration is a type that can hold a set of constant values that are defined by the user. Once you define an enumeration you can use it like integer types.E.g. enum {OFF, ON};The enum defines two integer constants called enumerators and these constants are assigned values by default. The value assigned to OFF = 0 and ON = 1. The above is an unnamed enumeration, however an enum can be named. E.g. enum STATE {OFF, ON};Each enumeration is a distinct type and the type of the enumeration is the enumerator. For example OFF is of type STATE. An enumerator can optionally be initialized by a constant expression of integral type. E.g. enum {WHITE = 3, BLACK = 5}; A value of an integral type can be converter to an enumeration type. This needs to be done explicitly. The results are undefined unless the value is within the range of the enumeration.E.g. enum COLORS {RED = 1; BLUE = 3, WHITE = 7};COLORS c1 = COLORS (5); All enumerators are converted to integral type for any arithmetic operation.