User-Defined Structures

A structure or struct is a user-defined collection of data. It is superior to using arrays because each item can have a different type and a different name. In the following section, you will see the advantages of using user-defined structures.

Arrays Are Not Enough

Data often appears in groups, or aggregates. For example, in the case study in Chapter 3, “Arrays and Algorithms,” which performs a simple stock price analysis, there are five numbers for each trading day: the four prices and the trading volume. Similarly, measurements from a meteorological station would include temperatures, air pressure, wind speed and direction, and so on. In these cases, all the numbers could be floating-point numbers, so an array could ...

Get C++ By Example: UnderC Learning Edition 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.