Three enumeration methods
(1)
# Include
Enum ENUM_TEST {ENUM_EST1 = 1, ENUM_EST2, ENUM_EST3, hour, ENUM_EST5, hour, ENUM_EST10,}; int main () {enum ENUM_TEST enum_test; enum_test = ENUM_EST10 + 1; printf ("enum_test = % d \ n", enum_test); return 0 ;}result: enum_test = 11
(2)
# Include
Enum {ENUM_EST1 = 1, ENUM_EST2, numbers, ENUM_EST4, numbers, ENUM_EST9, ENUM_EST10,} ENUM_TEST; int main () {ENUM_TEST = ENUM_EST10 + 1; printf ("enum_test = % d \ n", ENUM_TEST); return 0;} result: enum_test = 11
(3)
# Include
Typedef enum {ENUM_EST1 = 1, ENUM_EST2, ENUM_EST3, numeric, ENUM_EST5, numeric, ENUM_EST10,} ENUM_TEST; int main () {ENUM_TEST enum_test; enum_test = ENUM_EST10 + 1; printf ("enum_test = % d \ n", enum_test); return 0 ;}result: enum_test = 11
Note 1:
Assign a value to the enumerated variable. If the value exceeds the enumerated value range, the result is uncertain, as shown in the preceding three examples.
NOTE 2:
The last enumeration element can have either "," or "no"
NOTE 3:
The first method is to declare the enum_test variable with enum ENUM_TEST instead of ENUM_TEST. Both methods can be used in C ++.
Both the first and third types are declared;
The second and third usages, although only one typedef keyword is different, have different meanings. The second usage declares an enumeration variable, the third method is to declare an enumeration type.