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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: These mentioned things are presented in container adapters.
4. What will be the output of the following C++ code?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue<int> myqueue;
myqueue.push(12);
myqueue.push(75);
myqueue.back() -= myqueue.front();
cout << myqueue.back() << endl;
return 0;
}
a) 12
b) 75
c) 63
d) 74
View Answer
Explanation: In this program, We used the queue operation and performed the back operation. Because of that operation, We got the output as 63.
Output:
$ g++ sca.cpp $ a.out 63
5. What will be the output of the following C++ code?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue<int> myqueue;
int sum (0);
for (int i = 1; i <= 10; i++)
myqueue.push(i);
while (!myqueue.empty())
{
sum += myqueue.front();
myqueue.pop();
}
cout << sum << endl;
return 0;
}
a) 51
b) 52
c) 54
d) 55
View Answer
Explanation: 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?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> mypq;
mypq.push(30);
mypq.push(100);
mypq.push(25);
mypq.push(40);
while (!mypq.empty())
{
cout << " " << mypq.top();
mypq.pop();
}
cout << endl;
return 0;
}
a) 100 40 30 25
b) 100 40 30
c) 100 40
d) 100 30 25
View Answer
Explanation: 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?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> myints;
cout << (int) myints.size();
for (int i = 0; i < 5; i++) myints.push(i);
cout << (int) myints.size() << endl;
return 0;
}
a) 05
b) 15
c) 24
d) 102
View Answer
Explanation: 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?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> mystack;
mystack.push(10);
mystack.push(20);
mystack.top() -= 5;
cout << mystack.top() << endl;
return 0;
}
a) 10
b) 20
c) 13
d) 15
View Answer
Explanation: 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
View Answer
Explanation: 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!
View Answer
Explanation: It is used to decide the priority of two elements to be inserted in the queue.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Check Computer Science Books
- Practice Computer Science MCQs
- Apply for C++ Internship
- Practice Programming MCQs
- Check Programming Books