Previous: Chapter 12
Up: Chapter 12
Previous Page: Chapter 12
Next Page: 12.1 Structures

12 Structures and Unions

So far, we have seen one kind of compound (user defined) data type - the array and in Chapters and have seen how we can group information into one common data structure. However, the use of arrays is limited to cases where all of the information to be grouped together is of the same type. In this chapter we present the other compound data type provided in C - the structure, which removes the above limitation. We will discuss structures, pointers to structures, and arrays of structures. As with our previous data types, we will see how such structures can be declared; how information in them can be accessed, and how we can pass and return structures in functions. We will also see how arrays of structures are sorted and searched. We illustrate these points with several example programs.

Finally, we will introduce unions which are similar to structures; however, the elements in the union share the same memory cells. In a union, different types of data may be stored in a variable but at different times.


tep@wiliki.eng.hawaii.edu
Sat Sep 3 07:12:43 HST 1994