Home : C Language : Variables : Enumerations
Enumeration variables are declared thus:
enum
[enum_name]{
- item_name
[
=
constant],
- item_name
[
=
constant],
- item_name
[
=
constant]}
[var_name,
var_name];
where the optional var_names are variables declared to be of this enumeration type, and the optional enum_name is a name for this enumeration type which may be used in subsequent variable declarations of the form:
enum
enum_namevar_name
;
Each item_name is used as a symbol for the integer constant value specified. If no constant value is given, it defaults to one more than the value of the previous item_name in the enumeration list. The first item_name defaults to a value of zero if no constant value is given.
An enumeration variable should only be assigned values listed in its enumeration list.