> For the complete documentation index, see [llms.txt](https://tanias-workspace.gitbook.io/tanias-little-corner/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tanias-workspace.gitbook.io/tanias-little-corner/data-structures/array.md).

# Array

## What is an Array?

An array is a data structure used in programming to store a collection of elements, typically of the same data type, in a contiguous block of memory. Each element in the array can be accessed using an index, with the first element typically at index 0. Arrays are useful for storing multiple items, such as numbers or strings, where you need to perform operations like searching, sorting, or iterating over the elements.

For example, in C++:

<figure><img src="/files/adoBlRQ6DDYOkVLIniTg" alt=""><figcaption></figcaption></figure>

Here, `myArray` is an array of six integers. You can access the elements using their index, like `myArray[0]` for `4`, `myArray[1]` for `5`, and so on.

Arrays are fundamental in programming because they provide a way to organize and manipulate large amounts of data efficiently.

## Example:

In this example, the array `numbers` stores five integers. The `for` loop iterates through the array, printing each element along with its index,

<figure><img src="/files/XRDIhZsSxutSrTiCBF6T" alt=""><figcaption></figcaption></figure>

&#x20;The output would be:

<figure><img src="/files/KFsJ1FnAC1u9ptUIX1Hk" alt=""><figcaption></figcaption></figure>
