Introducing structs
Structs in V allow you to define composite objects. They facilitate you to create complex data structures, allowing its fields to have different data types. The fields of the struct can be primitive data types, enums, or could be another struct.
We will start understanding structs by observing their basic syntax. Later, we will learn how to define a struct based on this syntax, initialize a struct with values assigned to its fields, and access those fields. We will then discuss what heap structs are and illustrate this with detailed code examples.
Defining a struct
You can define a struct in V by using the struct
keyword followed by the name of the struct. The basic syntax of a struct in V is of the form shown here:
struct STRUCTNAME { FIELDNAME1 DATATYPE FIELDNAME2 DATATYPE }
For example, let's define a Note
struct to understand how a real-world...