section 6.3: Arrays of Structures

page 132

In the previous section we introduced pointers to structures and functions returning structures without fanfare. But now let's pay attention to the fact that structures fit the pattern of the other types: a structure is a type, so we can have pointer-to-struct, array-of-struct, and function-returning-struct. (We can also say, following our ongoing pattern of recursive definitions, that for any list of types t1, t2, t3, ..., we can make a new type

	struct tag {
		t1 m1;
		t2 m2;
		t3 m3;
		...
	};
which is a structure composed of members of those types.)

page 134

We glossed over the binary search routine on page 58 in section 3.3, so we can skip the details of this one, too. This illustrates another benefit of breaking functionality out into functions, though: as long as you know what a function does, you can understand a program that it's in without necessarily understanding all of it. In this case, binsearch searches an array tab, containing n cells of type struct key, looking for one whose word field matches the parameter word. If it finds a matching cell, it returns its index in the array; otherwise, it returns -1.


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback