Search⌘ K
AI Features

Types of Array

Explore different types of arrays in C++, classified by size and dimensions. Understand static and dynamic arrays, and discover the use of one-dimensional and multidimensional arrays to manage complex data efficiently.

In the previous lesson, we learned what arrays are, how they are indexed, and how they are stored in memory. In this lesson, we will look at how arrays are classified, both by their size and by their dimensions.

Classification of arrays

Arrays can be classified in two ways:

  • By their size

  • By their dimensions

Classification by size

Based on their size, arrays can be classified into two types: static and dynamic. Each differs in how memory is allocated and how much flexibility the array offers. Let us look at each one in turn.

Static arrays

A static array has a fixed size that is set at the time it is created. The number of elements is fixed at compile time and does not change during program execution.

A static array of size 10
A static array of size 10

Think of it like a printed scorecard with exactly ten rows. If we bowl an eleventh game, there is no room to record it. We would have to start a new, larger scorecard entirely if we want to keep a record of the eleventh game. The original card cannot grow.

This approach is simple and memory-efficient. The computer allocates exactly as much space as needed, nothing more. The trade-off is inflexibility. If we need more space than we originally planned for, we will need to create a new, larger ...