Search⌘ K
AI Features

Types of Array

Explore how arrays in Go are classified by their size and dimensions. Understand fixed-size and dynamic arrays, how slices enable dynamic behavior, and learn to work with one-dimensional, two-dimensional, and multidimensional arrays to represent complex data structures.

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: fixed-size arrays and dynamic arrays. Each differs in how memory is allocated and how much flexibility it offers. Let’s look at each one in turn.

Fixed-size arrays

A fixed-size array has a size that is set when it is created. In Go, an array’s length is part of its type, so the number of elements does not change during program execution.

A fixed-size array of size 10
A fixed-size 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 ...