What value does an enumeration object have if it is set to a value not equal to any of its respective enumeration constants?
Consider the following code:
<
Variable qux is not going to hold any of the enums values. Its value will be equal to 42 in the underlying type the compiler selects to represent foobar, which is implementation-defined. This would not present a problem when the value is 42, but it may become an issue when the constant does not fit in the type selected by the compiler for your enumeration.
One of the reasons why the compiler allows assignments of values other than enum constants is to support "flag" enumerations, when constants are expected to be combined in bitwise operations:
enum foobar {
foo = 1
, bar = 2
, baz = 4
} test = (foo | baz);
Variable test above holds the value of 5, which does not correspond to any of the enum constants.