Structures form a very large building block with which to collect like data into one collective unit. They are a versatile data structure in which to clump data together in convenient little packages! They are essentially classes with all members defined as public access with no private or protected access modes available. They are most commonly used for conglomerating data and also support member functions, but that attribute is rarely used. I believe this is because when multiple functions are involved, the need for private and protected variables and functions increases.

Definition and Syntax
Arrays are one of the most widely used data structures in programming languages. One downfall of using such a data type is that one must use homogeneous data types, an array can only hold multiple items of the same type. Structures overcome this problem by allowing the programmer to have an unlimited number of items of different data types! Objects contained within the structure are referred to as a members. Here’s an example of what a structure declaration looks like:
Here’s our general structure definition in Example 1. We use the struct keyword followed by a name for the structure. This name must be defined if we would like to make multiple copies of our structure. If we only need one instance, we can declare copyname as our instance name and disregard the name field. We can use listname[x] if we would we know that we will be immediately needing x copies of our structure.

In Example 2, we have declared our structure and have members that we can access. Before we can actually access any members, we have to have a copy to work with. This is called an instance. So far we have created a so-called template for constructing copies of the Games structure, but we still haven’t actually made one. We can create a copy 2 different ways. We can make a copy in our declaration, or we can declare one later on in our code.

Download pdf Using Structures in C++