Google News
logo
CPP - Quiz(MCQ)
A)
It is a sequence container that encapsulates dynamic size arrays
B)
It manages the memory
C)
It manages the length and size
D)
It is a sequence container that encapsulates static size arrays

Correct Answer : Option (A) :   It is a sequence container that encapsulates dynamic size arrays


Explanation : Vector in the container library contains sequence container that manipulates and encapsulates dynamic size arrays.

2 .
What will be the output of the following C++ code?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main()
    {
        vector<int> v;
        v.assign( 10, 42 );
        for (int i = 0; i < v.size(); i++) 
        {
            cout << v[i] << " ";
        }
    }
A)
42
B)
42 42
C)
424
D)
42 for 10 times

Correct Answer : Option (D) :   42 for 10 times


Explaination :

In this program, We used the vector to print the 42 for 10 times.
Output :
$ g++ std.cpp
$ a.out
42 42 42 42 42 42 42 42 42 42

A)
Memory interface
B)
Storage interface
C)
Allocator interface
D)
Memory management

Correct Answer : Option (C) :   Allocator interface


Explanation : Allocator interface in the container is required for storage management.

A)
Memory storage locations
B)
Contiguous storage locations
C)
Non-contiguous storage locations
D)
Contiguous & Non-contiguous storage locations

Correct Answer : Option (B) :   Contiguous storage locations


Explanation : Vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements

A)
Using Single & Double linked list
B)
Using Single linked list
C)
Using linear linked list
D)
Using Double linked list

Correct Answer : Option (D) :   Using Double linked list


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.

A)
multimap
B)
map
C)
set
D)
unordered map

Correct Answer : Option (A) :   multimap


Explanation : C++ provide multimap container that is used to make map that can contain same keys i.e. {a: 5} and {a:10} both can exist.

A)
Memory interface
B)
Restricted interface
C)
More interface
D)
No interface

Correct Answer : Option (B) :   Restricted interface


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.

A)
Arrays
B)
Static arrays
C)
Associative arrays
D)
Functional Arrays

Correct Answer : Option (C) :   Associative arrays


Explanation : Associative containers refer to a group of class templates in the standard library of the C++ programming language that implements ordered associative arrays.

A)
functional iterators
B)
Single directional iterators
C)
Bi-directional iterators
D)
Single & Bi-directional directional iterators

Correct Answer : Option (C) :   Bi-directional iterators


Explanation : Bi-directional iterator are used to move in both direction from any element i.e. both forward and backward movements are allowed.

A)
Generic
B)
Polymorphic
C)
Virtual
D)
Both Polymorphic & Generic

Correct Answer : Option (A) :   Generic


Explanation : The STL is a generic library, meaning that its components are heavily parameterized.