C++ Standard Library C++ STL Library

C++ <initializer_list> - end() Function



The C++ <initializer_list> end() function returns a pointer to the past-the-last element of the initializer_list. The past-the-last element of the initializer_list is the theoretical element that follows the last element. It does not point to any element, and hence could not be dereferenced.

This function is overloaded end() function.

C++ begin end

Syntax

template<class E> const T* 
  end (initializer_list<T> il) noexcept;
template<class E> constexpr const T* 
  end (initializer_list<T> il) noexcept;

Parameters

No parameter is required.

Return Value

Returns a pointer to the past-the-last element of the initializer_list.

Time Complexity

Constant i.e, Θ(1).

Example:

In the example below, end() function is used to access and print all elements of an initializer_list.

#include <iostream>
#include <initializer_list>
using namespace std;
 
int main (){
  initializer_list<int> ilist{10, 20, 30, 40, 50};

  //printing content of the initializer_list
  cout<<"ilist contains: ";
  for(auto it = begin(ilist); it != end(ilist); ++it)
    cout<<*it<<" ";

  return 0;
}

The output of the above code will be:

ilist contains: 10 20 30 40 50

❮ C++ <initializer_list> Library

5