Data Structures 

C Programming Tutorial 

Go to the Table of Contents


Uses for struct variables. Structure diagrams.

Data structures are organized patterns of data. The purpose of building a data structure is to create a pattern of information which models a particular situation clearly and efficiently. Take the simplest kind of data structure: the array. Arrays are good for storing patterns of information which look like tables, or share a tabular structure. For example, a chess board looks like a two dimensional array, so a chess game would naturally use a two dimensional array to store the positions of pieces on the chess board. The aim of a data structure is to model real life patterns with program data.

Most real application programs require a more complex data structure than C variables can offer; often arrays are not suitable structures for a given application. To see this, consider an application example in which a program stores a map of the local countryside. This program has to store information about individual towns and it has to be able to give directions to the user about how to get to particular towns from some reference point. In real life, all of this information is most easily conveyed by means of a map, with towns' vital statistics written on it. (See figure 1.) The diagram shows such a simplified map of the surrounding land. This sort of map is, ideally, just what a computer ought to be able to store. The handicap is that the map does not look very computerish. If the map is ever going to be stored in a computer it will need to look more mechanical. A transformation is needed. In order to make the map into a more computer-like picture, it must be drawn as a structure diagram.

A structure diagram is a picture which shows how something is connected up. Most often a structure diagram shows how a problem is connected up by relating all the parts which go together to make it up. In this case, the structure diagram just shows how program data are related to each other.