Enum variable
enum Weekend{
sat, sun};
Press the enumeration element at compile time constantProcessing, each enumeration element is an integer and the default is 0,1,2,3,... ,
you can also manually specify the value of the enumeration element :
enum Weekend{
sat = 6, sun};//人为赋值 之后 自动按顺序+1
But be aware that you can no longer assign values to enumeration elements latersat = 1
-wrong!
Enumeration elements can be directly referenced:
enum Weekend day = sat;//相当于day=0
printf("%d", sun);
When assigning a value to an enumeration variable, you cannot directly assign an integer, because the two are not of the same type, you can assign a value after type conversion, such as:
day = (enum Weekend) 6;//与day = sat;效果相同