Introduction of the concept of consortium and community
01——Introduction of the concept of consortium and community
Sometimes the same memory space stores different types, and variables of different types share a space.
- Structural elements have their own separate space, and common body elements share space. The size of the space is determined by the largest type.
- Define a union:
- Define a union variable:
- Calculate the length of the union:
Unions/unions are like structures but with differences:
02——Pay attention to the data coverage problem of the union
Struct elements do not affect each other, and assignment to a union will cause overwriting.
03——Unit development case
Example question expansion: