Posted in All Posts, Semester 2

Structures in C

We have seen that arrays can be used to represent  a group of data items of same data type, such as int or float. But we can not use an array to store data items of multiple data types. There structures came into play. Structures are a mechanism in C that allow packing data of different data types.

Structure, a constructed data type is a convenient tool for handling a group of logically related items.
For eg. A structure student can hold multiple values of multiple data types like roll no (integer), name (string) etc.
Examples of other structures :
time – seconds, minutes, hours
city – name, country, population
date – day, month, year

Defining a Structure-

Unlike arrays, structures must be defined first for their format that may be used later to declare structure variables. struct is a keyword used to define structures in C.

The variables in the structure (title, author, pages, price) are called member variables or structure elements.
The structure name is also called tag name.
P.S. : The member variables don’t occupy any space until they are associated with a structure variable.

Points to notice :
1. The definition is terminated with a semicolon.
2. While the entire definition is considered as a statement, each member is declared independently for its name and type in a separate statement inside the template.
3. The tag name such as book in the eg. will be used to declare structure variables of is type.

We hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

Learn Structure Syntax.

Suggested Reading

2 thoughts on “Structures in C

Comment your thoughts

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