...

/

Composite Types: Fixed and Dynamic Arrays

Composite Types: Fixed and Dynamic Arrays

Learn about composite types and the difference between fixed and dynamic arrays.

We'll cover the following...

Composite types

Sometimes, we need to store more than one value at a time. To do this, we can use what are called composite types.

A composite type is a data type that is made up of more than one value. There are situations when keeping several related values together makes sense. In our everyday life, we do this often. A shopping list is an example of this. Instead of having several papers, each one having one item we need to buy, we store all the items on one piece of paper and call this a list.

This is how a composite type works in programming as well. We have several types that all have some specific characteristics. The first one can be used when we want to represent a sequence or list of things. This is often called an array.

An array—also called a vector, list, or sequence—is a data type that stores several elements. This number can be fixed or flexible.

Fixed array

When we have a fixed-size array, we say how many slots we want it to have when we create it. This size won’t change. If we create an array that can store 10 integers, it will reserve space for 10 integers, even if we only use 3 or 5.

Typically, we would create a fixed-size ...