250+ TOP MCQs on Sequence Adapters and Answers

This section on C++ programming interview questions and answers on “Sequence Adapters”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ programming interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ language programming interview questions on “Sequence Adapters” along with answers, explanations and/or solutions:

1. What do container adapter provide to interface?
a) Restricted interface
b) More interface
c) No interface
d) Memory interface
Answer: a
Clarification: A container adapter provides a restricted interface to a container.In particular, adapters do not provide iterators; they are intended to be used only through their specialized interfaces.

2. What does the sequence adaptor provide?
a) Insertion
b) Deletion
c) Interface to sequence container
d) Insertion & Deletion
Answer: c
Clarification: Sequence adaptor provides interface to sequence container.

3. Which are presented in the container adaptors?
a) stack
b) queue
c) priority_queue
d) all of the mentioned
Answer: d
Clarification: These mentioned things are presented in container adapters.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     #include   
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         queue<int> myqueue;
  7.         myqueue.push(12);
  8.         myqueue.push(75);  
  9.         myqueue.back() -= myqueue.front();
  10.         cout << myqueue.back() << endl;
  11.         return 0;
  12.     }

a) 12
b) 75
c) 63
d) 74
Answer: c
Clarification: In this program, We used the queue operation and performed the back operation. Because of that operation, We got the output as 63.
Output:

5. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         queue<int> myqueue;
  7.         int sum (0);
  8.         for (int i = 1; i <= 10; i++) 
  9.             myqueue.push(i);
  10.         while (!myqueue.empty())
  11.         {
  12.             sum += myqueue.front();
  13.             myqueue.pop();
  14.         }
  15.         cout << sum << endl;
  16.         return 0;
  17.     }

a) 51
b) 52
c) 54
d) 55
Answer: d
Clarification: In this program, We used the push and pop operation of quueue to find out the total of all the number from 1 to 10.
Output:

$ g++ sca1.cpp
$ a.out
55

6. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         priority_queue<int> mypq;
  7.         mypq.push(30);
  8.         mypq.push(100);
  9.         mypq.push(25);
  10.         mypq.push(40);
  11.         while (!mypq.empty())
  12.         {
  13.             cout << " " << mypq.top();
  14.             mypq.pop();
  15.         }
  16.         cout << endl;
  17.         return 0;
  18.     }

a) 100 40 30 25
b) 100 40 30
c) 100 40
d) 100 30 25
Answer: a
Clarification: In this program, We used priority_queue and with that we are pushing and popping out the elements.
Output:

$ g++ sca2.cpp
$ a.out
100 40 30 25

7. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         stack<int> myints;
  7.         cout  << (int) myints.size();
  8.         for (int i = 0; i < 5; i++) myints.push(i);
  9.         cout  << (int) myints.size() << endl;
  10.         return 0;
  11.     }

a) 05
b) 15
c) 24
d) 102
Answer: a
Clarification: In this program, We declared myints and not initialized in first option, So it’s value is 0 and on another, We are pushing 5 values, So it’s size is 5.
Output:

$ g++ sca3.cpp
$ a.out
05

8. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         stack<int> mystack;
  7.         mystack.push(10);
  8.         mystack.push(20);
  9.         mystack.top() -= 5;
  10.         cout << mystack.top() << endl;
  11.         return 0;
  12.     }

a) 10
b) 20
c) 13
d) 15
Answer: d
Clarification: In this program, We used top option and this will return the reference to the next element.
Output:

$ g++ sca4.cpp
$ a.out
15

9. In which context does the stack operates?
a) FIFO
b) LIFO
c) Both FIFO & LIFO
d) LIFI
Answer: b
Clarification: A stack is a container where elements operate in a LIFO context, where elements are inserted (pushed) and removed (popped) from the end of the container.

10. Which operator is used in priority queue?
a) operator<
b) operator>
c) operator)
d) operator!
Answer: a
Clarification: It is used to decide the priority of two elements to be inserted in the queue.

  250+ TOP MCQs on Abstract Classes and Answers Quiz

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top