Home »
Aptitude Questions and Answers »
C++ Aptitude Questions and Answers
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++?
- The deque stands for the double-ended queue.
- The deque is a sequence container.
- The deque is a derived container.
- In the deque container, data can be inserted and deleted from both the front and back ends the side.
Options:
- A and B
- A, C, and D
- A, B, and D
- C and D
Correct Answer - 3
A, B, and D
Explanation:
Statements A, B, and D are correct about deque container in C++.
2) Which of the following header file is required to use deque container in C++?
- <queue>
- <deque>
- <dqueue>
- <cqueue>
Correct Answer - 2
<deque>
Explanation:
The <deque> header file is required to use deque container in C++.
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:
- 10 20 30
- Garbage Value
- Syntax error
- Runtime error
Correct Answer - 3
Syntax error
Explanation:
The above code will generate a syntax error. Because add() function is not available in deque class.
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:
- 10 20 30
- Garbage Value
- Syntax error
- Runtime error
Correct Answer - 3
Syntax error
Explanation:
The above code will generate a syntax error. Because the header file for deque is not included.
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:
- 10 20 30
- 20 10 30
- 30 10 20
- Syntax error
Correct Answer - 2
20 10 30
Explanation:
The above code will print "20 10 30" on the console screen.
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:
- 10 20 40
- 10 40
- 20 40
- Syntax error
Correct Answer - 3
20 40
Explanation:
The above code will print "20 40" on the console screen.
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:
- 10 20 30 40
- 10 20 40
- 10 30 40
- Syntax error
Correct Answer - 4
Syntax error
Explanation:
The above code will generate syntax error due to insert() function.
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:
- 10 20 30 40
- 10 40 20 30
- 10 30 40 20
- Syntax error
Correct Answer - 2
10 40 20 30
Explanation:
The above code will print "10 40 20 30" on the console screen.
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:
- 10 20 30 40
- 10 40 40 20 30
- 10 2 40 20 30
- Syntax error
Correct Answer - 2
10 40 40 20 30
Explanation:
The above code will print "10 40 40 20 30" on console screen.
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:
- 10 20 30 30
- 10 20 40 30
- Garbage value
- Syntax error
Correct Answer - 1
10 20 30 30
Explanation:
The above code will print "10 20 30 30" on console screen.
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:
- 40
- Garbage value
- Runtime error
- Syntax error
Correct Answer - 3
Runtime error
Explanation:
The above code will generate a runtime 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:
- 20
- 30
- 40
- Syntax error
Correct Answer - 2
30
Explanation:
The above code will print "30" on the console screen.
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:
- 10 20 30 40
- 20 30 40
- Garbage value
- Syntax error
Correct Answer - 4
Syntax error
Explanation:
The above code will generate 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:
- 10
- 20
- 40
- Syntax error
Correct Answer - 2
20
Explanation:
The above code will print "20" on the console screen.
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:
- 10 20 30 40
- 40 30 20 10
- 40 30 10 20
- Syntax error
Correct Answer - 3
40 30 10 20
Explanation:
The above code will print "40 30 10 20" on the console screen.
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:
- 10 20 30 40
- 20 10 30 40
- 40 30 10 20
- Syntax error
Correct Answer - 4
Syntax error
Explanation:
The above code will generate a 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:
- 10 20 30
- Garbage value
- No output
- Syntax error
Correct Answer - 3
No output
Explanation:
The above code will not print anything on the console screen.
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:
- 10 20 30
- Garbage value
- No output
- Syntax error
Correct Answer - 1
10 20 30
Explanation:
The above code will print "10 20 30" on the console screen.
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:
- 10 20 30
- Garbage value
- No output
- Syntax error
Correct Answer - 4
Syntax error
Explanation:
The above code will generate a syntax error on the console screen.
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:
- 10
- 30
- Garbage value
- Syntax error
Correct Answer - 2
30
Explanation:
The above code will print "30" on the console screen.
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:
- 10 20 30
- Garbage value
- Syntax error
- Runtime error
Correct Answer - 3
Syntax error
Explanation:
The above code will generate a syntax 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:
- 10 20 30
- Garbage value
- Syntax error
- Runtime error
Correct Answer - 1
10 20 30
Explanation:
The above code will print "10 20 30" on the console screen.
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:
- 10 20 30
- Garbage value
- Syntax error
- Runtime error
Correct Answer - 1
10 20 30
Explanation:
The above code will print "10 20 30" on the console screen.
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:
- 0
- Garbage value
- Syntax error
- Runtime error
Correct Answer - 1
0
Explanation:
The above code will print "0" on the console screen.
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:
- 10
- 20
- Syntax error
- Runtime error
Correct Answer - 3
Syntax error
Explanation:
The above code will generate a syntax error.