struct
1, structure and array of differences: can be declared in the structure of the array; struct variables can be assigned to each other, and arrays are not.
2. The difference between struct and class: class's member access rights are private by default, while struct members are public.
3, the definition of structural body:
(1) can be recursive. Inside a struct, you can use pointers to point to yourself. For example, a linked list.
(2) can be nested. A struct can contain other structures within it.
4, the bit field in the structure.
When storing information, you do not need to occupy a full byte, but only a few or one bits.
Union
Structs and common bodies are composed of several different types of data type members, but at any one time, only one of the selected members is stored in the common body. and the structural body
in all the members are pure. For different member assignments of a common body, overrides are made to the other members, and the value of the original member does not exist.
(1) The structure occupies memory, which may exceed the amount of the memory of each member, while the shared body occupies the maximum memory for each member.
(2) The order in which union and struct is stored in memory is stored from the ground address.
big-endian storage: High bytes of data are stored in low addresses. Small-End Storage: Low bytes of data are stored in low addresses.
Enum
(1) Definition
Enum Enum type name
{
Enumerate tables
}
For example:
Enum COLORENUM1
{
Red,//Note that the system assigns a value of 0 to it by default
Blue,//The system is assigned a value of 1
Black,//system is assigned a value of 2
Pink//System is assigned a value of 3
}
Enum COLORENUM2
{
Red = 1,//The user assigns the value itself so the enumeration is a set of symbolic name/value pairs
Blue,//The system is assigned a value of 2
Black = 1,//user-assigned value 1
Pink//System is assigned a value of 2
}
As you can see, the system assigns a value to a constant that is not assigned, but the value is assigned in the same way as the previous value +1.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
struct, Union, enum