1. How many items are there in sequence container?
A. 2
B. 3
C. 4
D. 5
Answer: D
Explanation:
: There are five items in sequence container. They are array, vector, list, forward_list and dequeue.
2. Which of the following class template are based on arrays?
A. vector
B. list
C. dequeue
D. both vector & dequeue
Answer: D
Explanation:
: Class template vector and class template dequeue both are based on arrays.
3. Which of the following will return the new element at the end of container?
A. front
B. back
C. push_back
D. pop_
Answer: B
Explanation:
: back() in containers are used to access the last element of the sequence.
4. What will be the output of the following C++ code?
#include<iostream>
#include <deque>
using namespace std;
int main ()
{
deque mydeque (5);
deque::reverse_iterator rit = mydeque.rbegin();
int i = 0;
for (rit = mydeque.rbegin(); rit!= mydeque.rend(); ++rit)
*rit = ++i;
for (deque :: iterator it = mydeque.begin();
it != mydeque.end(); ++it)
cout << ' ' << *it;
return 0;
}
A. 12345
B. 1234
C. 54321
D. 43210
Answer: C
Explanation:
: In this program, We used the operation of rbegin and rend on dequeue and produced the result.
5. What will be the output of the following C++ code?
#include<iostream>
#include<deque>
using namespace std;
int main ()
{
unsigned int i;
deque a (3,100);
deque b (5,200);
a.swap(B.;
cout << "a contains:";
for (deque::iterator it = a.begin(); it != a.end(); ++it)
cout << ' ' << *it;
cout << "b contains:";
for (deque::iterator it = b.begin(); it != b.end(); ++it)
cout << ' ' << *it;
return 0;
}
A. a contains: 200 200 200 200 200b contains: 100 100 100
B. a contains: 100 100 100 100 100b contains: 200 200 200
C. a contains: 200 200 200 200 200b contains: 200 200 200
D. a contains: 200 200 200 200 200b contains: 100 200 150
Answer: A
Explanation:
: In this program, We swapped the values of both dequeues and printing the dequeues.
6. What will be the output of the following C++ code?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int i;
deque mydeque;
mydeque.push_back (100);
mydeque.push_back (200);
mydeque.push_back (300);
for(deque :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
{
}
mydeque.clear();
mydeque.push_back (110);
mydeque.push_back (220);
for(deque :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
A. 110
B. 220
C. Both 110 & 220
D. 330
Answer: C
Explanation:
: In this program, We cleared the old values presented in the dequeue with the new values.
7. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector myvector;
int * p;
unsigned int i;
p = myvector.get_allocator().allocate(5);
for (i = 0; i < 5; i++)
myvector.get_allocator().construct(&p[i], i);
for (i = 0; i < 5; i++)
cout << ' ' << p[i];
for (i = 0; i < 5; i++)
myvector.get_allocator().destroy(&p[i]);
myvector.get_allocator().deallocate(p, 5);
return 0;
}
A. 1 2 3 4 5
B. 0 1 2 3 4
C. 1 2 3 4
D. 5 4 3 2 1
Answer: B
Explanation:
: In this program, We allocated the values to the vector by using get allocater and then we are destroying it.
8. What will be the output of the following C++ code?
#include <iostream>
#include <cmath>
#include <list>
using namespace std;
bool same_integral_part (double first, double seconD.
{
return ( int(first) == int(seconD. );
}
struct is_near
{
bool operator() (double first, double seconD.
{
return (fabs(first - seconD. < 5.0);
}
};
int main ()
{
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
list mylist (mydoubles, mydoubles + 10);
mylist.sort();
mylist.unique();
mylist.unique (same_integral_part);
mylist.unique (is_near());
for (list :: iterator it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
-
using namespace std;
bool same_integral_part (double first, double seconD.
{
return ( int(first) == int(seconD. );
}
struct is_near
{
bool operator() (double first, double seconD.
{
return (fabs(first - seconD. < 5.0);
}
};
int main ()
{
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
list
A. 2.72 12.15 72.25
B. 12.15 73.0 12.77
C. 73.35
D. 74.45
Answer: A
Explanation:
: In this program, We are eliminating the values by using the unique operation in the list.
9. How the list containers are implemented?
A. Using Double linked list
B. Using Single linked list
C. Using Single & Double linked list
D. Using linear linked list
Answer: A
Explanation:
: List containers are implemented as doubly-linked lists. Doubly linked lists can store each of the elements they contain in different and unrelated storage locations.
10. Which of the following does not support any insertion or deletion?
A. Array
B. Vector
C. Dequeue
D. List
Answer: A
Explanation:
: Because array is not dynamic in nature, So they can’t be manipulated.
- 10+ TOP C++ MCQs on OOPs Concept – 2
- 10+ TOP C++ MCQs on OOPs Concept – 3
- 10+ TOP C++ MCQs on Integer Types
- 10+ TOP C++ MCQs on References – 2
- 10+ TOP C++ MCQs on Objects
- 10+ TOP C++ MCQs on Operator Functions
- 10+ TOP C++ MCQs on Function Call
- 10+ TOP C++ MCQs on Abstract Classes – 2