Enum (enum)
Enumerations are a collection of named Integer constants, which are common in everyday life.
For example, the sunday,monday,tuesday,wednesday,thursday,friday,saturday of the week is an enumeration.
The descriptions of enumerations are similar to structs and unions in the form of:
Enum Enumeration Name {
identifier [= integer constant],
identifier [= integer constant],
...
identifier [= integer constant],
Enumerate variables;
If the enumeration is not initialized, that is, when the "= Integer Constant" is omitted, the first identifier begins, and the identifier 0,1,2 is assigned sequentially .... However, when a member of an enumeration is assigned a value, subsequent members determine its value by the rule of 1 in turn.
For example, after the following enumeration descriptions, the x1,x2,x3,x4 values are 0,1,2,3.
Enum string{x1, x2, X3, x4}x;
When the definition changes into:
Enum string
{
X1,
X2=0,
X3=50,
X4,
}x;
Then X1=0, x2=0, x3=50, x4=51
Attention:
1. Each member (identifier) Terminator in the enumeration is ",", not ";", and the last member can omit ",".
2. You can assign a negative number when initializing, and then the identifier will add 1 in turn.
3. An enumeration variable can only take an identifier constant in the enumeration description structure.
For example:
Enum string
{
X1=5,
X2,
X3,
X4,
};
Enum Strig x=x3;
At this point, the enumeration variable x is actually 7.