If a variable requires several possible values, it can be defined as an enumeration type. The reason for enumeration is to enumerate the possible values of variables or objects.
For example, to make everyone better understand that there is a pen in a pencil, but you don't know what it is before you open it, it may be a pencil or a pen. There are two possibilities, so you can define an enumeration type to represent it!
Enum box {penpencil, pen}; // here you define a variable of Enumeration type called box, the enumerated variable contains two elements, the pencil and pen, respectively.
Here, if you want to define two variables with the same Enumeration type, you can use the following two methods to define them!
Enum box {penpencil, pen };
Enum box box2; // or abbreviated to box box2;
Another way is to define the statement at the same time.
Enum {penpencil, pen} box, box2; // define the statement at the same time!
The enumeration Element System in enumeration variables is processed according to constants.Enumerated constantThey cannot assign values to ordinary arithmetic tasks. Writing and sending such a statement is incorrect, but you can assign values when declaring it!
Enum box {penpencil = 1, pen = 2 };
However, if you do not assign values to elements, the system automatically increments the values from 0, if you only define the first element, the system adds 1 to the value of the previous element to the next element. For example
Enum box {penpencil = 3, pen}; // here pen is 4. The system will automatically assign values to pen = 4!