CHAPTER OUTLINE
12.1 Introduction
12.2 Features of Structures
12.3
Declaration and Initialization of Structures
12.4
Structure Within Structure
12.5
Array of Structures
12.6 Pointer to Structure
12.7 Structure and Function
12.8 Typedef
12.9 Bit FieldsS
12.10 Enumerated Data Type
12.11
Union
12.12
Calling Bios and Dos Services
12.13 Union of Structures
Exercises
12.1 INTRODUCTION
You are aware that a variable stores a single value of a data type. Arrays can store many values of
similar data type. Data in the array is of the same composition in nature as far as type is concerned. In
real life we need to have different data types for example to maintain employees information we
should have information such as name, age, qualification, salary etc. Here, to maintain the information
of employees dissimilar data types are required. Name and qualification of the employee are char data
type, age is integer, and salary is float. All these data types can not be expressed in a single array. One
may think to declare different arrays for each data type. But there will be huge increase in source codes
of the program. Hence, arrays can not be useful here. For tackling such mixed data types, a special
feature is provided by C It is known as structure.
A structure is a collection of one or more variables of different data types, grouped together under a
single name. By using structures we can make a group of variables, arrays, pointers etc.
12.2 FEATURES OF STRUCTURES
To copy elements of one array to another array of same data type elements are copied one by one. It is
not possible to copy all the elements at a time. Whereas in structure it is possible to copy the contents
of all structure elements of different data types to another structure variable of its type using assignment
(=) operator. It is possible because the structure elements are stored in successive memory locations.
Nesting of structures is possible i.e. one can create structure within the structure. Using this feature
one can handle complex data types.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.147.193