C++ std::array Functions

About This Index
This page is the C++ std::array Functions index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs.
Learn what a std::array is on /cpp/array. Use this page when you need a specific member function such as at(), size(), or fill().
A std::array<T, N> never grows or shrinks, so it has no push_back(), insert(), or resize(). It has the 17 functions below.
How to Call an Array Function
Include <array>, create the array, and call members with a dot:
#include <array>
#include <iostream>
std::array<int, 5> nums = {4, 8, 15, 16, 23};
std::size_t n = nums.size(); // 5
int second = nums.at(1); // 8, checked
nums.fill(0); // every element becomes 0
auto it = nums.begin(); // iterator to the first element C++ std::array Functions Table
All function guides in this C++ tutorial series (17 tutorials), grouped by purpose.
Element access
4 functionsRead or change elements by position.
Capacity
3 functionsAsk about the size. For std::array the size is fixed.
Iterators
8 functionsWalk through the array forwards or backwards. The c versions are read-only.
| Function | Description | Tutorial |
|---|---|---|
begin() | Get an iterator to the first element. | Try it |
end() | Get an iterator one past the last element. | Try it |
cbegin() | Get a read-only iterator to the first element. | Try it |
cend() | Get a read-only iterator past the last element. | Try it |
rbegin() | Get a reverse iterator to the last element. | Try it |
rend() | Get a reverse iterator past the first element. | Try it |
crbegin() | Get a read-only reverse iterator to the last element. | Try it |
crend() | Get a read-only reverse iterator past the first element. | Try it |
Operations
2 functionsChange the whole array in one call.
Frequently Asked Questions
Start with at()
Read an element by index and learn about std::out_of_range.
12 people found this page helpful
