After the test, I found that the code below is not standardized. Several types of the enumeration must be all uppercase letters.
1. Non-assigned Enumeration type
[Html]
# Include "stdio. h"
Enum weekday
{Sun, mon, tue, wed, thu, fri, sat} a, B, c;
Main (){
A = sun;
B = mon;
C = tue;
Enum weekday d, e, f;
D = wed;
E = thu;
F = fri;
Printf ("% d, % d \ n", a, B, c, d, e, f );
}
Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ cc main. c-o main
Pateo @ pateo-B86N53X :~ /Work/study $./main
0, 1, 2, 3, 4, 5
2. Start enumeration of Values
[Html]
# Include "stdio. h"
Enum weekday
{Sun = 0x0009, mon, tue, wed, thu, fri, sat} a, B, c;
Main (){
A = sun;
B = mon;
C = tue;
Enum weekday d, e, f;
D = wed;
E = thu;
F = fri;
Printf ("% d, % d \ n", a, B, c, d, e, f );
}
Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ cc main. c-o main
Pateo @ pateo-B86N53X :~ /Work/study $./main
9, 10, 11, 12, 13, 14
3. Special Value assignment
[Html
# Include "stdio. h"
Enum weekday
{Sun = 0x0009, mon, tue, wed = 0x0003, thu, fri, sat} a, B, c;
Main (){
A = sun;
B = mon;
C = tue;
Enum weekday d, e, f;
D = wed;
E = thu;
F = fri;
Printf ("% d, % d \ n", a, B, c, d, e, f );
}
Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ cc main. c-o main
Pateo @ pateo-B86N53X :~ /Work/study $./main
9, 10, 11, 3, 4, 5
4. Repeat special
[Html]
# Include "stdio. h"
Enum weekday
{Sun = 0x0009, mon = 5, tue, wed = 0x0003, thu = 7, fri = 2, sat = 9} a, B, c;
Main (){
A = sun;
B = mon;
C = tue;
Enum weekday d, e, f, g;
D = wed;
E = thu;
F = fri;
G = sat;
Printf ("% d, % d \ n", a, B, c, d, e, f, g );
}
Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ cc main. c-o main
Pateo @ pateo-B86N53X :~ /Work/study $./main
9, 5, 6, 3, 7, 2, 9