> For the complete documentation index, see [llms.txt](https://enma-1.gitbook.io/enma/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enma-1.gitbook.io/enma/addons/arrays.md).

# Arrays & Vectors

Three carriers, exactly C++: builtin fixed arrays `T a[N]`, heap blocks `new T[N]`, and the library containers `std::vector<T>` / `std::array<T, N>`.

## Builtin fixed arrays — `T a[N]`

```cpp
int64 a[4];                       // frame or file scope
int32 b[3] = {1, 2, 3};           // brace init
char  s[] = "hi";                 // sized from the literal (3 incl. NUL)
int64 m[2][3];                    // 2D, row-major

a[0] = 5;
int64* p = &a[0];                 // decay to element pointer; &a[4] (one past
                                  // the end) is a valid address
```

Elements are contiguous at their natural width (`int8`/`int16`/`int32`/ `float32` pack like C), so a decayed `T*` walks the same bytes natives see. `int8`/`int16` alias `char`/`wchar` — signedness follows the spelling.

Indexing carries **no runtime checks** — an out-of-bounds index is UB, exactly C++. A **provable constant** index outside the bounds is a compile error (`a[4]` on `int64 a[4]`, per-dimension for 2D); the one-past-the-end address `&a[N]` stays legal.

Arrays are not assignable or member-accessible as objects (`a = b`, `a.size()` reject) — use the extent you declared, or a container.

## Heap blocks — `new T[N]` / `delete[]`

```cpp
It* xs = new It[8];               // default-constructs each element
xs[3].v = 7;
delete[] xs;                      // destroys each element, frees the block
```

Runtime-sized (`new T[n]`) works the same. `T*` arithmetic and subscripts use the element stride.

## std::vector\<T>

Growable, contiguous, value-semantic. From the `std` prelude.

```cpp
std::vector<int64> v = {1, 2, 3};
v.push_back(4);
v[0] = 10;                        // T& operator[] — writes go through
for (int64 x : v) { ... }

v.size()   v.empty()   v.capacity()
v.at(i)    v.front()   v.back()
v.data()                          // T* to the buffer
v.reserve(n)   v.resize(n)
v.pop_back()                      // void, exactly C++
v.insert(v.begin() + i, x)        // iterator position
v.erase(v.begin() + i)
v.clear()
v.begin()  v.end()                // iterators: * ++ == and it + n
```

Copying a vector deep-copies its elements; `push_back` copies the argument in (one user copy-constructor fire per push, exactly C++).

## std::array\<T, N>

Fixed-size value struct with C++-exact layout: `sizeof == N * sizeof(T)`, elements at offset 0, usable wherever a flat `T[N]` blob is expected.

```cpp
std::array<int64, 4> a;
a[1] = 5;                         // T& operator[] — unchecked
a.at(9);                          // bounds-checked: throws

a.size()   a.max_size()   a.empty()
a.front()  a.back()
a.data()                          // raw T*
a.fill(x)
a.swap(other)
a.begin()  a.end()
```

## Algorithms (namespace std)

Free function templates — they instantiate only where called:

```cpp
std::sort(v)                      // ascending via the element's operator<
std::sum(v)                       // vector<int64>
std::join(v, ", ")                // vector<string> / vector<int64> / vector<wstring>
std::transform(v, (int64 x) => x * 2)
std::filter(v, (int64 x) => x > 0)
std::any_of(v, pred)   std::all_of(v, pred)
std::next(it)          std::next(it, n)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://enma-1.gitbook.io/enma/addons/arrays.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
