What will be the output of the following C++ code?
#include<iostream>
#include<iterator>
#include<vector>
using namespace std;
int main()
{
vector<int> ar = { 1, 2, 3, 4, 5 };
vector<int>::iterator ptr = ar.begin();
ptr = next(ptr, 3);
cout << *ptr << endl;
return 0;
}
#include<iostream>
#include<iterator>
#include<vector>
using namespace std;
int main()
{
vector<int> ar = { 1, 2, 3, 4, 5 };
vector<int>::iterator ptr = ar.begin();
ptr = next(ptr, 3);
cout << *ptr << endl;
return 0;
}A. 1
B. 2
C. 3
D. 4
Answer: Option D

Join The Discussion