C Programming

STRUCTURES
A Structure is a data type suitable for grouping data elements together. Lets create a new data structure suitable for storing the date. The elements or fields which make up the structure use the four basic data types. As the storage requirements for a structure cannot be known by the compiler, a definition for the structure is first required. This allows the compiler to determine the storage allocation needed, and also identifies the various sub-fields of the structure.


	struct   date {
		int  month;
		int  day;
		int  year;
	};

This declares a NEW data type called date. This date structure consists of three basic data elements, all of type integer. This is a definition to the compiler. It does not create any storage space and cannot be used as a variable. In essence, its a new data type keyword, like int and char, and can now be used to create variables. Other data structures may be defined as consisting of the same composition as the date structure,


	struct  date   todays_date;

defines a variable called todays_date to be of the same data type as that of the newly defined data type struct date.


©Copyright B Brown. 1984-1999. All rights reserved.