enumeration type enum
Declaration form:
enum enumeration type name {variable value list};
like:
enum Weekday {SUN,MON,TUE,WED,THU,FRI,SAT};
Treat enumeration elements as constants, and cannot assign values to them
SUN=0;
Enum elements have default values, which are 0,1,2,... at a time
In the above example, the value of SUN is 0, MON is 1, TUE is 2, ..., SAT is 6
Values can also be defined separately at declaration time:
enum Weekday {SUN=7,MON=8,TUE,WED,THU,FRI,SAT};
Define SUN as 7, MON as 1, add 1 in the following sequence, and SAT as 6
Enumeration values can perform relational operations
Integer values cannot be directly assigned to enumeration variables (if necessary, type conversion should be performed)
application:
typedef declaration
grammatical form
typedef existing type name new type name list;
There can be multiple identifiers in the new type name table, separated by commas
For example:
typedef double Area, Volume;
typedef int Natural;
Natural i1, i2;
Area a;
Volume in;
----------C++ language study notes----------