Handling Array of Structures in C Programming


Structures are user defined, heterogeneous data types. i.e. it can hold several members of dissimilar types as well. Real life entities, objects around us, cannot be modeled just by arrays, they have several information which are of different  types. For example, our course book has ISBN:String, cost:float, numberOfPages: int, bookTitle:String, etc.

General syntax to declare a structure:

For our example,

will declare a structure of CourseBook. Now, we can create structure variables, aka, variables of structure types with the following syntax:

The members of the structure can be accessed using the structure variable. No members can be added later to the structure, dynamically. The syntax to access the members of the structure using the structure variable and a period operator (.) aka dot operator would look like:

In some case if we like to omit the keyword ‘struct‘ while declaring the structure variable, we can simply use the keyword, typedef while declaring the structure with an alias.

Then, while declaring the structure variable, we could have just said,

A simple program to demonstrate the use of array of structure to demonstrate the concept of handling members of structures with the help of structure variables and period operator:


Would You Mind Sharing?


Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.