ABSTRACT

This chapter introduces two new types: structures and unions. Like arrays, structures and unions group a set of values into a single entity. Both help to organize data in a more natural way. However, their properties are quite different from an array's. Unlike arrays, the members of a structure or union may have different types. The chapter discusses how to declare structures and unions types, declare variables, and perform operations on them. The most common method to access a structure member is to write the name of the structure variable followed by the dot operator and the name of the member. A pointer to a structure member is used like an ordinary pointer. A structure may contain one or more structures. A nested structure must be declared before the declaration of the structure in which it is contained; otherwise, the compiler will produce an error message. A structure may contain fields whose length is specified as a number of bits.