So far, we have been using C's basic types--char, int, long int, double, etc.--and a few derived types--arrays of basic types, pointers to basic types, and functions returning basic types. In this chapter, we'll learn about another way to derive types: by building user-defined types.
There's an old joke about Henry Ford saying that you could get the Model T in any color you wanted, as long as it was black. User-defined data types have a little bit of the same restriction: you don't have ultimate flexibility; you can define your own data types any way you want, as long as they're collections of other types. (What you couldn't define would be data types that held, say, tractors or teddy bears or Model T Fords, because of course computers have no way of holding those objects. You're ultimately restricted to the primitive types of data which computers can represent, and C's basic types cover most of those.)
Very roughly speaking, a structure is a little bit like an array. An array is a collection of associated values, all of the same type. A structure is a collection of associated values, but the values can all have different types.
15.2: Accessing Members of Structures
15.3: Operations on Structures
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1996-1999 // mail feedback