C++ std::array Functions

Beginner
6 min read
Updated: Nov 2026
17 function guides
Function index

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().

Fixed size.

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:

C++
#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 functions

Read or change elements by position.

FunctionDescriptionTutorial
at()Read or change one element by index, with a bounds check.Try it
front()Get the first element of the array.Try it
back()Get the last element of the array.Try it
data()Get a raw pointer to the array memory.Try it

Capacity

3 functions

Ask about the size. For std::array the size is fixed.

FunctionDescriptionTutorial
empty()Check whether the array has zero elements.Try it
size()Get the number of elements in the array.Try it
max_size()Get the largest number of elements the array can hold.Try it

Iterators

8 functions

Walk through the array forwards or backwards. The c versions are read-only.

FunctionDescriptionTutorial
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 functions

Change the whole array in one call.

FunctionDescriptionTutorial
fill()Set every element to the same value.Try it
swap()Swap the contents with another array of the same type and size.Try it

Frequently Asked Questions

They are the functions you call on a std::array object with a dot, such as nums.size(), nums.at(2), nums.fill(0), or nums.begin(). They need #include <array>.
This tutorial series covers 17: at, front, back, data, empty, size, max_size, begin, end, cbegin, cend, rbegin, rend, crbegin, crend, fill, and swap.
The size of a std::array is fixed at compile time. It cannot grow or shrink, so functions such as push_back(), insert(), erase(), and resize() do not exist. Use std::vector if you need them.
at() checks the index and throws std::out_of_range for a bad one. operator[] does not check, so a bad index is undefined behavior.
Read the C++ std::array page first. Then open at(), size(), fill(), and begin() from the tables below.

Start with at()

Read an element by index and learn about std::out_of_range.

at() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful