Unit 3: Working with Simple Data Structures
Data structures are just ways to store multiple data values. Arrays, structs, enumerations, unions, queues, lists, and vectors are a few examples of data structures. In this unit, we will focus on a few simple structures. The array is one of the most basic structures used in computer programming. Arrays store data contiguously by representing data with a common name and distinguishing it by its index. This is like a parking garage: the garage stores vehicles; all of the parking spaces have a common name (the name of the garage); and each parked vehicle is identified by a specific parking space number. This is also true of arrays. Think of arrays as parking garages for our data. After exploring arrays, we then learn structs, unions, and enumerations, which are special ways to group more complex data types.
Completing this unit should take you approximately 8 hours.
Upon successful completion of this unit, you will be able to:
- use arrays; and
- use struct, unions, and enumerations.
Arrays are the most basic data structure in C++. Read this page to learn about arrays.
Watch these videos about the different features and types of arrays.
Watch this video to learn about multidimensional arrays.
3.2: Structs, Unions, and Enumerations
Enumerated types (enums) are essentially a series of int variables that represent more complex data types.
Structs are a great way to pair multiple variables together and allow them to be passed as a group. Unions are very similar to structs, but the data shares the same memory spaces, so they cannot be used at the same time.
Unions are very similar to structs, but the data shares the same memory spaces, so they cannot be used at the same time.
Unit 3 Exercises
Complete these exercises to test your understanding of arrays.
Complete these assessments to test your understanding of arrays and how to use them.