C++ List Container Aptitude Questions and Answers

C++ List Container Aptitude: This section contains C++ List Container Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on March 07, 2021

1) There are the following statements that are given below, which of them are correct about list container in C++?

  1. A list container class is a derived container.
  2. The list supports bi-directional iteration.
  3. The list stores elements in the contiguous memory location.
  4. The traversing of the list element is slow compared to the vector.

Options:

  1. A and B
  2. A, B, and C
  3. B, C, and D
  4. A, B, C, and D

2) Which of the following header file is required to use list container class in C++?

  1. <list>
  2. <List>
  3. <Ilist>
  4. <Linkedlist>

3) Can we access elements from the list randomly?

  1. Yes
  2. No

4) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;

    L.push_back(10);
    L.push_back(20);

    for (int i = 0; i < L.size(); i++) {
        cout << L[i] << " ";
    }

    return 0;
}

Options:

  1. 10 20
  2. Garbage value
  3. Syntax error
  4. Runtime error

5) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;

    L.push_back(10);
    L.push_back(20);

    for (int i = 0; i < L.size(); i++) {
        cout << *L++ << " ";
    }

    return 0;
}

Options:

  1. 10 20
  2. 20 10
  3. Syntax error
  4. Runtime error

6) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);

    for (I = L.begin(); I != L.end(); ++I)
        cout << *I << " ";

    return 0;
}

Options:

  1. 10 20
  2. 20 10
  3. Syntax error
  4. Runtime error

7) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);

    for (I = L.begin(); I != L.end();)
        cout << *++I << " ";

    return 0;
}

Options:

  1. 10 20
  2. 20 10
  3. Syntax error
  4. Runtime error

8) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);

    for (I = L.begin(); I != L.end();)
        cout << *++I++ << " ";

    return 0;
}

Options:

  1. 10 20
  2. 20 10
  3. Syntax error
  4. Runtime error

9) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20
  2. 20 10
  3. Syntax error
  4. Runtime error

10) What is the correct output of the given code snippet?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_front(30);
    L.push_back(40);

    L.pop_back();
    L.pop_back();

    cout << L.front();

    return 0;
}

Options:

  1. 10
  2. 20
  3. 30
  4. 40

11) What is the correct output of the given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    const list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_back(30);
    L.push_back(40);

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. Syntax error
  4. Runtime error

12) What is the correct output of given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_back(30);
    L.push_back(40);

    L.reverse();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. Syntax error
  4. Runtime error

13) What is the correct output of given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<string> L;
    list<string>::iterator I;

    L.push_back("India ");
    L.push_back("is ");
    L.push_back("great ");
    L.push_back("country ");

    I.reverse();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. India is great country
  2. country great is India
  3. Syntax error
  4. Runtime error

14) What is the correct output of the given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L1;
    list<int> L2;

    list<int>::iterator I;

    L1.push_back(10);
    L1.push_back(20);

    L2.push_back(30);
    L2.push_back(40);

    L1.merge(L2);

    for (I = L2.begin(); I != L2.end(); ++I)
        cout << *I << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. No output
  4. Syntax error

15) What is the correct output of the given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L1;
    list<int> L2;

    list<int>::iterator I;

    L1.push_back(10);
    L1.push_back(20);

    L2.push_back(30);
    L2.push_back(40);

    L1.merge(L2);

    for (I = L1.begin(); I != L1.end(); ++I)
        cout << *I << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. Syntax error
  4. No output

16) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(30);
    L.push_back(20);

    L.sort(1);

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. No output
  4. Syntax error

17) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(30);
    L.push_back(20);

    L.sort();
    L.reverse();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 40 30 20 10
  3. No output
  4. Syntax error

18) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(10);
    L.push_back(20);
    L.push_back(20);

    cout << L.unique();

    return 0;
}

Options:

  1. 0
  2. 40
  3. Syntax error
  4. Runtime error

19) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(10);
    L.push_back(20);
    L.push_back(20);
    L.push_back(40);

    L.unique();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 40 20
  2. 10 40 10 20 40
  3. Syntax error
  4. Runtime error

20) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(10);
    L.push_back(20);
    L.push_back(20);
    L.push_back(40);

    L.unique();
    L.sort();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 40
  2. 10 10 20 40 40
  3. Syntax error
  4. Runtime error

21) What is the correct output of the given code snippets?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(40);
    L.push_back(10);
    L.push_back(20);
    L.push_back(20);
    L.push_back(40);

    L.sort();
    L.unique();

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 40
  2. 10 10 20 40 40
  3. Syntax error
  4. Runtime error

22) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_back(30);
    L.push_back(40);

    L.assign(2, 12);

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 12 12 30 40
  2. 12 12
  3. Syntax error
  4. Runtime error

23) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_back(30);
    L.push_back(40);

    L.resize(3);

    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 10 20 30
  3. Syntax error
  4. Runtime error

24) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L;
    list<int>::iterator I;

    L.push_back(10);
    L.push_back(20);
    L.push_back(30);
    L.push_back(40);

    L.resize(3);
    L.resize(4);
    for (I = L.begin(); I != L.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 10 20 30 30
  3. 10 20 30 0
  4. Syntax error

25) What is the correct output of given code snippets in C++?

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> L1;
    list<int> L2;
    list<int>::iterator I;

    L1.push_back(10);
    L1.push_back(20);

    L2.push_back(30);
    L2.push_back(40);

    I = L1.begin();

    L1.splice(I, L2);

    for (I = L1.begin(); I != L1.end();)
        cout << *I++ << " ";

    return 0;
}

Options:

  1. 10 20 30 40
  2. 30 40 10 20
  3. 40 30 20 10
  4. Syntax error






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.