Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language explains enumeration types.
C language explains enumeration types.
If the enumeration is not initialized, that is, "= integer constant" is omitted, the identifiers , 1, 2, ... However, when a member in the enumeration assigns a value, the subsequent members determine its value according to the rule of

plus 1 in turn.

for example, after the following enumeration, the values of x1, x2, x3, x4 and x4 are , 1, 2 and 3 respectively.

enum Num{x1, x2, x3, x4}x;

when the definition is changed to:

enumnum

{

x1,

x2 = ,

x3 = 5,

x4

} x;

then x1=, x2=, x3=5, x4=51

Note:

1. The terminator of each member (identifier) in the enumeration is ",",not ";" , the last member can be omitted

",".

2. You can assign a negative number during initialization, and the identifiers in the future will still be incremented by 1.

3. Enumeration variables can only take an identifier constant in the enumeration description structure.

for example:

enumnum

{

x1 = 5,

x2,

x3,

x4

};

enum Num x=x3;

at this point, the enumeration variable x is actually 7.