Arrays of Structures
The inflatable structure contains an array (the name array). It’s also possible to create arrays whose elements are structures. The technique is exactly the same as for creating arrays of the fundamental types. For example, to create an array of 100 inflatable structures, you could do the following:
inflatable gifts[100]; // array of 100 inflatable structures
This makes gifts an array of inflatables. Hence each element of the array, such as gifts[0] or gifts[99], is an inflatable object and can be used with the membership operator:
cin >> gifts[0].volume; // use volume member of first structcout << gifts[99].price << endl; // display price member of last struct
Keep in mind that gifts itself is an array, not a structure, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access