Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <list>
    using namespace std;
    int main ()
    {
    list<int> ListData;
    list<int> :: iterator Iter1, Iter2;
    for (int k = 0; k < 12; ++k) ListData.push_back(k * 2);
    Iter1 = Iter2 = ListData.begin();
    advance (Iter2, 7);
    ++Iter1;
    Iter1 = ListData.erase (Iter1);
    Iter2 = ListData.erase (Iter2);
    ++Iter1;
    --Iter2;
    ListData.erase (Iter1, Iter2);
    for (Iter1 = ListData.begin(); Iter1 != ListData.end(); ++Iter1)
    cout << ' ' << *Iter1;
    return 0;
    }
    1. 22
    2. 20 22
    3. 18 20 22
    4. 12 16 18 20 22
    5. 0 4 12 16 18 20 22
Correct Option: E

In this program, We are comparing the values in both lists and erasing it according to certain condition.



Your comments will be displayed only after manual approval.