Structure

Structures or structs helps implement custom user-defined data types. A structure is a composite data type, consisting of multiple variables of different data types. They are very similar to contracts; however, they do not contain any code within them. They consist of only variables.

There are times when you would like to store related data together. Suppose you want to store information about an employee, say the employee name, age, marriage status, and bank account numbers. To represent this, these individual variables related to single employee, a structure in Solidity can be declared using the struct keyword. The variables within a structure are defined within opening and closing {} brackets as shown in the following screenshot: ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.