<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/out-of-bounds-array-access",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Out-of-bounds array access"
}
-->

# Out-of-bounds array access

Detects out-of-bounds access of arrays.

## Overview

Use this check to detect attempts to access indexes that exceed the array’s bounds. Out-of-bounds array accesses have undefined behavior, and can result in crashes or incorrect program output. Available in Xcode 9 and later.

> Note: This check doesn’t detect out-of-bounds accesses into heap-allocated arrays.

### Out-of-bounds array access in C

In the following example, out-of-bounds access of `array` occurs on the last iteration of the loop:

```occ
int array[5];
for (int i = 0; i <= 5; ++i) {
    array[i] += 1; // Error: out-of-bounds access on the last iteration
}
```

#### Solution

Ensure that accessed indexes don’t exceed the array’s bounds.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)