# Arrays

An array can hold multiple values of a specific type. The memory must be preallocated.

The structure of a variable of array type:

```ebnf
<array_type> ::= <typename> "[" ","+ "]"
<expression_list> ::= <expression> "," <expression_list> | <expression>
<array_expression> ::= "[" <expression_list> "]"
```

Simple Example:

```sc
let primes : i32[] = [2, 3, 5, 8, 11, 13];
```

A value of the array can be accessed though the index operator in square brackets. Every item has an index to indentify an element. An index starts at zero, so the first element is accessable at index 0, the second element is accessible at index 1 and so on. The index has to be within the bounds of the array. It cannot be negative or greater than or equal to the length of the array.

```sc
print(primes[1]); //access the 2. element
```

An item in the array can be also changed, even if the variable that contains it is not mutable.

```sc
primes[3] = 7;
```

The example above is an array of 1 dimension. You can also define arrays of more dimensions to build a matrix.

To declare a n-dimensional array:

```sc
let matrix : i32[,] = [[0, 1], [1, 0]];
let element = matrix[0, 0];
```

## Exercises

1. Declare an array containing the first ten prime numbers and print it to the console.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://furesoft.gitbook.io/socordia/the-basics/variables/arrays.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
