Enumeration
In practical problems, the values of some variables are restricted to a limited range. For example, there are only seven days in one weeks, only 12 months a year, and six courses a week in one class, and so on. If these quantities are described as integers, the character type or other types are clearly not appropriate. For this reason, the C language provides a type called enumeration. All possible values are enumerated in the definition of the enumeration type, and the value of the variable that is described as the "enum" type cannot exceed the defined scope. It should be explained that the enumeration type is a basic data type, not a constructed type, because it can no longer be decomposed into any basic type.
Enumeration type definition and enumeration variable description
One, the general form of enumeration definition enumerated type is:
Enum enum Name
{enumeration value table};
All available values should be listed in the enumeration value table. These values are also called enumeration elements.
For example: Enum weekday
{Sun,mou,tue,wed,thu,fri,sat};
The enumeration is named weekday and has a total of 7 enumerated values, that is, seven days of the week. Any value that is described as a weekday type variable can only be one day of seven days.
Description of enumerated variables as with structs and unions, enumeration variables can also be described in different ways, that is, to define a description, and to define a description or a direct description. Where a variable a,b,c is described as the weekday mentioned above, any one of the following methods may be used:
Enum Weekday
{
......
};
Enum weekday a,b,c or as: Enum weekday
{
......
}a,b,c; or: enum
{
......
}a,b,c;