vector rend() in C++

rend(): It returns a read/write reverse iterator that points to one before the first element in the vector.

Note: Iteration is done in reverse element order. 

File: stl_vector.h

Parameter: No parameters required.

Syntax:

vector<data_type>::reverse_iterator iteratorName = vecName.rend()

For Example:

vec  ={1,2,3,4}

vec.rend() => It points one before the first element (i.e 1).

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {1234};

    vector<int>::reverse_iterator it = vec.rend();

    cout << *(it - 1<< "\n";
    
    return 0;
}


No comments:

Post a Comment