> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/const-arrays.md).

# Const Arrays

Const arrays are basically compiler managed lists of data stored in the data section.

### Syntax

```gpc
// single dimensional
const <datatype> <n>[] = { <values> };

// two dimensional
const <datatype> <n>[][] = {
    { <values for the first "row"> },
    { <values for the second "row"> }
};
```

The difference between a single dimension array and a multi dimensional array is that the single dimension array is basically a single row with related data while a multi dimensional array allows for slightly better structured data of rows.

An example of when a multi dimensional array is preferred is when setting up values for different guns in a game. You can then have each row represent a single gun and the columns within have each value for it.

There is an important rule to keep in mind when working with multi dimensional arrays: each row must contain exactly the same number of values.

There is also an importance of choosing an appropriate data type, it will dictate what values you can use within the array. See the below table for more information about the available datatypes, their support, size, and range:

| Datatype | Supports Multi-Dimension Arrays | Size Required Per Value                    | Minimum Value  | Maximum Value |
| -------- | ------------------------------- | ------------------------------------------ | -------------- | ------------- |
| `int8`   | Yes                             | 8 bits (1 byte)                            | -128           | 127           |
| `uint8`  | Yes                             | 8 bits (1 byte)                            | 0              | 255           |
| `int16`  | Yes                             | 16 bits (2 bytes)                          | -32,768        | 32,767        |
| `uint16` | Yes                             | 16 bits (2 bytes)                          | 0              | 65,535        |
| `int32`  | Yes                             | 32 bits (4 bytes)                          | -2,147,483,648 | 2,147,483,647 |
| `string` | No                              | 8 bits per character + 8 (1 byte + 1 byte) | N/A            | N/A           |

***

### Accessing Data

Similar to how the data section works, all indexes always begin at 0 within each row, meaning the first value is stored at 0. When you want to access the data within you do so using the below syntax:

```gpc
name[column];           // single dimensional
name[row][column];      // two dimensional
```

Below you'll see a couple of examples of how this works:

```gpc
const int8 single_dimension[] = { 0, 1, 2 };

const uint8 multi_dimension[][] = {
    { 0, 1, 2 },
    { 3, 4, 5 }
};

int a, b;

main {
    a = single_dimension[1];       // 1
    b = multi_dimension[1][2];     // 5
}
```


---

# 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:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/const-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.
