---
title: "subscript(_:)"
framework: swift
role: symbol
role_heading: Instance Subscript
path: "swift/unsafebufferpointer/subscript(_:)-9vykr"
---

# subscript(_:)

Accesses the element at the specified position.

## Declaration

```swift
subscript(i: Int) -> Element { get }
```

## Parameters

- `i`: The position of the element to access. i must be in the range 0..<count.

## Overview

Overview The following example uses the buffer pointer’s subscript to access every other element of the buffer: let numbers = [1, 2, 3, 4, 5] let sum = numbers.withUnsafeBufferPointer { buffer -> Int in     var result = 0     for i in stride(from: buffer.startIndex, to: buffer.endIndex, by: 2) {         result += buffer[i]     }     return result } // 'sum' == 9 note: Bounds checks for i are performed only in debug mode.
