Skip to Content (Press Enter)

Array

A data structure that stores a collection of elements, usually of the same type, in a specific order.

Each item in an array is called an element, and each element is assigned an index or position, which makes it easy to access specific elements directly.

Characteristics of an Array

  • Indexed: Elements are ordered and accessed by their index, starting from 0 (in most programming languages).

  • Fixed Size: In some languages, arrays have a fixed size set at creation, while other languages support dynamic arrays that can grow or shrink.

  • Homogeneous Elements: Typically, all elements in an array are of the same data type, like integers, strings, or objects.

Example of an Array

array = [2, 4, 6, 8, 10]

Here, array[0] would access the first element, 2.

Common Uses of Arrays:

  • Storing Data: Arrays are used to store lists of related data, such as names, scores, or coordinates.

  • Iterating Data: Arrays allow looping through elements efficiently to perform operations on each item.

  • Organizing Information: Arrays serve as the basis for more complex data structures like matrices, tables, and lists.

Arrays are fundamental in programming due to their simplicity and ability to quickly retrieve and organise multiple values.