VOOZH about

URL: https://www.geeksforgeeks.org/cpp/cend-function-in-cpp/

⇱ cend() Function in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

cend() Function in C++

Last Updated : 27 Nov, 2022

Cend() is the function defined in C++ STL. This function produces a constant random access iterator that identifies the deque's past-the-end element. If the container is empty then cend() function returns the same as cbegin() function. This member function's iterator can only be used to iterate containers; it cannot be used to change the content of the object it is pointing at. 

Syntax:

const_iterator cend() const noexcept;

A const_iterator is an iterator that points to constant content.

Example 1: Below is the C program to use cend() function in deque to print elements in reverse order:


Output
Elements of deque in reverse order: 
5 4 3 2 1 
  • Time Complexity: O(n) where n is the number of elements in the deque.
  • Auxiliary Space: O(1)

Example 2: Below is the C program to use cend() function in deque to print elements of deque:


Output
geeks for geeks 
  • Time Complexity: O(n) where n is the number of elements in the deque.
  • Auxiliary Space: O(1)
Comment