Introduction of Structures in C


So far, we have been dealing with variables that can hold one value at a time and arrays that can hold a number of values but all should be of same data type (i.e. group of homogeneous data items). But there are some situations where we want to store data items of different types as a single unit using a single name. In such a case, we can neither use simple variables nor an array. For instance, we want to store information of students in a class that include their rollno (int), name (string), marks (float type) and so on. Such type of related data items of different types cannot be grouped together using an array. In order to group such data items of different type, C provides a data type known as structure.


A structure is a collection of related data items which can be of different types held together in a single unit. The data items enclosed within a structure are known as its members which can either be of int, float, char etc. data types. As a structure may contain items of different types so it can be viewed as a collection of heterogeneous data items.



Previous                                                                                    Next


Powered by Blogger.