Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main () 
{
    vector<int> myvector;
    for (int i = 0; i < 10; i++) 
        myvector.push_back(i);
    typedef vector<int> :: iterator iter_int;
    reverse_iterator<iter_int> rev_iterator;
    rev_iterator = myvector.rend() - 4;
    cout << *rev_iterator << endl;
    return 0;
}

A. 2

B. 3

C. 4

D. 5

Answer: Option B


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it