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.

C++ begin end

Syntax

const T* end() const noexcept;
constexpr const T* end() const 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, the initializer_list::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};
  initializer_list<int>::iterator it;

  //printing content of the initializer_list
  cout<<"ilist contains: ";
  for(it = ilist.begin(); it != ilist.end(); ++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