Chapter 13 - Structures, Unions, and Miscellaneous Items
Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
Copyright 1998 The McGraw-Hill Companies
Chapter 13: Structures, Unions, and Miscellaneous Items
Overview
This chapter investigates several advanced C and C++ types, such as structures, unions, and bit-fields, along with other miscellaneous topics. You will learn how to create and use structures in programs. The chapter also covers how to pass structure information to functions, use pointers with structures, create and use unions in programs, and use other important features, such as typedef and enumerated types (enum).
The bulk of the chapter concentrates on two important features common to C and C++: the structure and the union. The C or C++ structure is conceptually an array or vector of closely related items. Unlike an array or vector, however, a structure permits the contained items to be of assorted data types.
The structure is very important to C and C++. Structures serve as the flagship of a more advanced C++ type, called the class. If you become comfortable with structures, it will be much easier for you to understand C++ classes. This is because C++ classes share, and expand upon, many of the features of a structure. Chapters 16 and 18 are devoted to the C++ class.
Unions are another advanced type. Unions allow you to store different data types at the same place in your system’s memory. These advanced data types serve as the foundation of most spreadsheet and database programs.
In the section that follows, you will learn how to build simple structures, create arrays of structures, pass structures and arrays of structures to functions, and access structure elements with pointers.