Enumerating the assignment of type variables and using
Enumeration types are used in the following terms:
1. The enumeration value is a constant, not a variable. You cannot assign a value to an assignment statement in a program. For example, the following assignment is made to the elements of the enumeration weekday: Sun=5;mon=2;sun=mon; are wrong.
2. The enumeration element itself is defined by the system as a numeric value that represents an ordinal, defined as 0,1,2 from the 0 start order .... In weekday, the sun value is the 0,mon value of 1, ..., and the SAT value is 6.
Main () {
Enum Weekday
{Sun,mon,tue,wed,thu,fri,sat} a,b,c;
A=sun;
B=mon;
C=tue;
printf ("%d,%d,%d", a,b,c);
}
3. You can only assign an enumeration value to an enumeration variable, and you cannot assign the value of an element directly to an enumeration variable. such as: A=sum;b=mon; is correct. and: A=0;b=1; Is wrong. If you have to assign a value to an enumeration variable, you must use coercion type conversion, such as: A= (enum weekday) 2, meaning that the enumeration element with order number 2 is given an enumeration variable A, which is equivalent to: a=tue; It should also be explained that enumeration elements are not literal constants or string constants, and do not use single or double quotes.
Main () {
Enum body
{a,b,c,d} month[31],j;
int i;
J=a;
for (i=1;i<=30;i++) {
Month[i]=j;
j + +;
if (j>d) j=a;
}
for (i=1;i<=30;i++) {
Switch (Month[i])
{
Case a:printf ("%2d%c\t", I, ' a '); Break
Case b:printf ("%2d%c\t", I, ' B '); Break
Case c:printf ("%2d%c\t", I, ' C '); Break
Case d:printf ("%2d%c\t", I, ' d '); Break
Default:break;
}
}
printf ("\ n");
}