1. Introduction:
C constants can be divided in to two major categories: Primary Constant, Secondary
Constant. Primary type of constant holds only single value or single character. Whereas
secondary types of constant holds multiple values or characters. The secondary constants are
array, structures, pointers, enumeration and union.
Structure is a user-defined data type in C which allows you to combine different data types to
store a particular type of record. Structure helps to construct a complex data type in more
meaningful way. It is somewhat similar to an Array. The only difference is that array is used
to store collection of similar data types while structure can store collection of any type of
data. Structure is used to represent a record. Suppose if it is required to store record
of Student which consists of student name, address, roll number and age then simple array
cannot store this information because here some fields are characters as well as numbers. In
short, data types are different. In such situation, a structure can be defined to hold this
information
Keyword struct is generally used whenever lot of data needs to be grouped together. For
example, it can be used to hold records from a database or to store information about
personal contacts in an address book. In the contacts, we can store name, address, phone
number, email etc.
In previous module, we have studied arrays. The array allows defining type of variables that
can hold several data items of the same kind. Similarly structure is another user defined data
type available in C that allows combining data items of different kinds, or we can say
structure is the collection of variables of different types under a single name for better
data handling.
2. Basics of structure
Structures are basically derived data types because they are constructed using objects of other
data types. C Structure is a collection of different data types which are grouped together and
each element in a C structure is called member. Basically Structure is used to store the
complicated data. A structure is a convenient way of grouping several pieces of related
information together.