c/language/enum

An enumerated type is a distinct whose value is a value of its underlying type (see below), which includes the values of explicitly named constants (enumeration constants).

Syntax
Enumerated type is declared using the following enumeration specifier as the in the :

@1@ Declares an enumeration without a fixed underlying type. @2@ Declares an enumeration of fixed underlying type.

where is a comma-separated list of, each of which has the form:

where

As with or, a declaration that introduced an enumerated type and one or more enumeration constants may also declare one or more objects of that type or type derived from it.

Explanation
Each that appears in the body of an enumeration specifier becomes an   in the enclosing scope and can be used whenever integer constants are required (e.g. as a case label or as a non-VLA array size).

If is followed by, its value is the value of that constant expression. If is not followed by, its value is the value one greater than the value of the previous enumerator in the same enumeration. The value of the first enumerator (if it does not use ) is zero.

The itself, if used, becomes the name of the enumerated type in the tags  and requires the use of the keyword enum (unless typedef'd into the ordinary name space).

Each enumerated type is  with one of:, a signed integer type, or an unsigned integer type. It is implementation-defined which type is compatible with any given enumerated type, but whatever it is, it must be capable of representing all enumerator values of that enumeration.

Enumerated types are integer types, and as such can be used anywhere other integer types can, including in and.