Skip to content
Related Articles

Related Articles

Improve Article

forward_list::cend() in C++ STL with Example

  • Difficulty Level : Easy
  • Last Updated : 12 Oct, 2018
Geek Week

forward_list::cend() is a function in C++ STL which returns a constant iterator pointing to the past-the-last element of the forward_list. The iterator returned by the function does not point to any element in the container, but to the position followed by the last element of the forward list container.

The iterator returned by the function points to constant content. Since the iterator itself is not constant it can be increased or decreased or modified but it cannot be used to modify its content even if the forward list is not constant.
Since the iterator does not point to any element of the forward list, it cannot be dereferenced in any case.



Parameters: The function does not take any parameter.

Return Value: The function returns an iterator pointing to the past-the-end element of the forward list container.

The following programs illustrates the use of the forward_list::cend() function:

// CPP program to illustrate
// forward_list::cend();
#include <forward_list>
#include <iostream>
using namespace std;
int main()
    // Initializing the forward list
    forward_list<int> sample = { 7, 54, 47, 48 };
    // Display sample
    cout << "sample: ";
    for (auto it = sample.cbegin();
         it != sample.cend();
        cout << *it << " ";
sample: 7 54 47 48
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :