C++ custom data type - enumeration and typedef

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:

238dab70b45c4e5a951373073b6dbad2.png

7feefef3c7e64f30b1f8cc4e5615b0d2.png 

 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----------

Guess you like

Origin blog.csdn.net/m0_57781693/article/details/129779452