ADVERTISEMENT
ADVERTISEMENT

C++ STL Deque Aptitude Questions and Answers

C++ STL Deque Aptitude: This section contains C++ STL Deque Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on March 09, 2021

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

  1. The deque stands for the double-ended queue.
  2. The deque is a sequence container.
  3. The deque is a derived container.
  4. In the deque container, data can be inserted and deleted from both the front and back ends the side.

Options:

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

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

  1. <queue>
  2. <deque>
  3. <dqueue>
  4. <cqueue>

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

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

int main()
{
    deque<int> d;

    d.add(10);
    d.add(20);
    d.add(30);

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

    return 0;
}

Options:

  1. 10 20 30
  2. Garbage Value
  3. Syntax error
  4. Runtime error

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

#include <iostream>
using namespace std;

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

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

    return 0;
}

Options:

  1. 10 20 30
  2. Garbage Value
  3. Syntax error
  4. Runtime error

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_front(20);
    d.push_back(30);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_front(20);
    d.pop_back();
    d.push_back(40);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    d.insert(40);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    deque<int>::iterator itr = d.begin();
    ++itr;

    d.insert(itr, 40);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    deque<int>::iterator itr = d.begin();
    itr++;

    d.insert(itr, 2, 40);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    deque<int>::iterator itr = d.end();
    itr++;

    d.insert(itr, 40);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

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

    cout << d.at(4);

    return 0;
}

Options:

  1. 40
  2. Garbage value
  3. Runtime error
  4. Syntax error

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

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

int main()
{
    deque<int> d;

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

    cout << d.at(2);

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

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

    int* p = d.at(1, 3);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

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

    cout << d.front();

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

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

    deque<int>::reverse_iterator ptr;
    for (ptr = d.rbegin(); ptr != d.rend(); ++ptr) {
        cout << *ptr << " ";
    }

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

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

    deque<int>::iterator ptr;
    for (ptr = d.rbegin(); ptr != d.rend(); ++ptr) {
        cout << *ptr << " ";
    }

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d1;

    deque<int> d2;

    d2.push_back(10);
    d2.push_back(20);
    d2.push_back(30);

    d2.operator=(d1);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d1;

    deque<int> d2;

    d2.push_back(10);
    d2.push_back(20);
    d2.push_back(30);

    d1.operator=(d2);

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d1;

    deque<int> d2;

    d2.push_back(10);
    d2.push_back(20);
    d2.push_back(30);

    d1.operator= d2;

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

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    cout << d.back();

    return 0;
}

Options:

  1. 10
  2. 30
  3. Garbage value
  4. Syntax error

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    for (int i = 0; i < d.size(); i++)
        cout << d.operator[i] << " ";

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    for (int i = 0; i < d.size(); i++)
        cout << d.operator[](i) << " ";

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    for (int i = 0; i < d.size(); i++)
        cout << d.operator[]((i)) << " ";

    return 0;
}

Options:

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

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    cout << d.operator[](3) << " ";

    return 0;
}

Options:

  1. 0
  2. Garbage value
  3. Syntax error
  4. Runtime error

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

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

int main()
{
    deque<int> d;

    d.push_back(10);
    d.push_back(20);
    d.push_back(30);

    cout << d.operator<>(1) << " ";

    return 0;
}

Options:

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



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.