C++ Array Library - end() Function


The C++ function std::array::end() returns an iterator which points to the past-end element of array.


Following is the declaration for std::array::end() function form std::array header.

iterator end() noexcept;
const_iterator end() noexcept;



Return Value

Returns an iterator pointing to the past-the-end element in the array. This element act as a place-holder and never stores the actual data that is why deferencing this location would result undefined behavior.

If array object is const-qualified, method return const iterator otherwise returns iterator.


This member function never throws exception.

Time complexity

Constant i.e. O(1)


The following example shows the usage of std::array::end() function.

#include <iostream>
#include <array>

using namespace std;

int main(void) {

   array<int, 5> arr = {10, 20, 30, 40, 50};
   /* iterator pointing at the start of array */
   auto start = arr.begin();   
   /* iterator pointing past−the−end of array */
   auto end = arr.end();      
   /* iterate complete array */
   while (start < end) {
      cout << *start << " ";

   cout << endl;

   return 0;

Let us compile and run the above program, this will produce the following result −

10 20 30 40 50