array::cbegin() and array::cend() in C++ STL
- array::cbegin() is a built-in function in C++ STL which returns a const_iterator pointing to the first element in the array. It cannot be used to modify the element in the array which is possible using array::begin().
Syntax:
array_name.cbegin()
Parameters: The function does not accept any parameters.
Return Value: The function returns a const_iterator pointing to the first element in the array.
Program 1:
// CPP program to illustrate// the array::cbegin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){array<int, 5> arr = { 1, 5, 2, 4, 7 };// Prints the first elementcout <<"The first element is "<< *(arr.cbegin()) <<"\n";// Print all the elementscout <<"The array elements are: ";for(autoit = arr.cbegin(); it != arr.cend(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The first element is 1 The array elements are: 1 5 2 4 7
- array::cend() is a built-in function in C++ STL which returns a const_iterator pointing to the theoretical element after the last element in an array.
Syntax:
array_name.cend()
Parameters: The function does not accept any parameters.
Return Value: The function returns a const_iterator pointing to the theoretical element after the last element in an array.
Program 1:
// CPP program to illustrate// the array::cend() function#include <bits/stdc++.h>usingnamespacestd;intmain(){array<int, 5> arr = { 1, 5, 2, 4, 7 };// prints all the elementscout <<"The array elements are: ";for(autoit = arr.cbegin(); it != arr.cend(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The array elements are: 1 5 2 4 7
Recommended Posts:
- Synchronous Chatting Application using C++ boost::asio
- C/C++ For loop with Examples
- How to input a comma separated string in C++?
- Program to Parse a comma separated string in C++
- Difference between Private and Protected in C++ with Example
- Difference between Inheritance and Polymorphism
- Difference between Single and Multiple Inheritance in C++
- Difference between Abstraction and Encapsulation in C++
- return statement in C/C++ with Examples
- C++ Program to Illustrate Trigonometric functions
- How to implement our own Vector Class in C++?
- Web Programming in C++
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
- fill_n() function in C++ STL with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



