Solidity Structs
The purpose of this article is to explore Solidity structs in depth, discussing their properties, use cases, and how to work with them effectively in smart contracts.
Using structural types, records can be represented. Let’s say you want to keep track of the books you own in a library.
It may be useful to track the following characteristics about each book:
- Title
- Author
- Subject
- Book ID
Define Struct
The struct keyword must be used to define a Struct. With the struct keyword, a new type of data can be defined that has more than one member.
Struct statements follow the following format
struct struct_name { type1 type_name_1; type2 type_name_2; type3 type_name_3; }
Example
struct Book { string title; string author; string subject; uint book_id; }
Access Struct and Its Variable
A structure member can be accessed by applying the member access operator (.).
This operator is defined as a period between the name of the structure variable and the name of the structure member we wish to access.
Structs are used to define variables of structure types.
The following program provides the basic understanding of solidity structures:
Example: 
We can also create an structure for a person as done below:
Example: 
Compile and check output yourself.
Conclusion
Solidity structs are a fundamental building block of smart contract development. With structs, you can define complex data structures that allow you to store and manipulate data in more meaningful ways.
By leveraging the power of structs, you can create more sophisticated and robust smart contracts that can stand up to the demands of real-world use cases.
So if you’re serious about building on the blockchain, learning about structs is a must.