Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
     #include <iostream>
    #include <iterator>
    #include <list>
    using namespace std;
    int main ()
    {
    list<int> DataList;
    for (int i = 0; i < 10; i++)
    DataList.push_back (i * 30);
    list<int> :: iterator firstIter = DataList.begin();
    list<int> :: iterator lastIter = DataList.end();
    cout << distance(firstIter, lastIter) << endl;
    return 0;
    }
    1. 10
    2. 30
    3. Compilation Error
    4. All of above
    5. None of these
Correct Option: B

In this program, We are printing the number of elements in the list by using distance method.



Your comments will be displayed only after manual approval.