Google News
logo
CPP - Quiz(MCQ)
A)
Outside the block
B)
Whole program
C)
Everywhere
D)
Only on that container

Correct Answer : Option (D) :   Only on that container


Explanation : A Container “owns” its elements: the lifetime of an element stored in a container cannot exceed that of the Container itself.

A)
Objects
B)
Pointers
C)
Values
D)
Methods

Correct Answer : Option (B) :   Pointers


Explanation : Pointers are legal iterators, so if your internal container is a simple C array, then all you need to do is return the pointers.

A)
Container interface requirements
B)
Iterator requirements
C)
Allocator interface requirements
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : These are the design specific requirements for building a container from the scratch.

A)
Iterator management
B)
Memory management
C)
Storage management
D)
Storage & Memory management

Correct Answer : Option (C) :   Storage management


Explanation : Storage management is the use of the allocator interface in the user-defined container.

A)
Heterogeneous container
B)
Homogeneous container
C)
Sequence container
D)
None of the above

Correct Answer : Option (A) :   Heterogeneous container


Explanation : Heterogeneous container is the name of the container which contains group of multiple objects.

A)
array<type,size> arr;
B)
Array<type,size> arr;
C)
array<type> arr;
D)
Array<type> arr;

Correct Answer : Option (A) :   array<type,size> arr;


Explanation : The declaration of array class starts with a keyword array followed by <> specifying the type and size of array and then the name of the identifier. Example: array<int, 10> arr; arr is an array class of type in with size = 10.

A)
at() is a member function of array class whereas get() is not
B)
get() takes array class as a parameter whereas at() takes a constant integer(i.e. index) as a parameter
C)
at() is available under <array> header file whereas get() is available under <tuple> header file
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : get() and at() differ in various ways. get() is not a part of array class, get is available under <tuple> header and get() takes array class also as a parameter to access the element.

A)
Swaps two elements of an array given elements
B)
Swaps two elements given indices of elements
C)
Swaps two arrays
D)
Swaps same elements of the array if required

Correct Answer : Option (C) :   Swaps two arrays


Explanation : swap() function is used to swap elements of two array classes provided the size of both arrays classes are same.

A)
To check whether an array is empty or not
B)
To check whether the size of an array is zero or not
C)
To check how many elements are there in the array
D)
To check whether an array contains negative elements or not

Correct Answer : Option (B) :   To check whether the size of an array is zero or not


Explanation : empty() function is used to check whether the size of an array class is zero or not. It is not used to check whether an array is empty or not. The function true only if size/max_size of an array is zero otherwise it returns false.

A)
both are same
B)
begin() returns returns first element cbegin() returns void
C)
begin() returns iterator to first element and cbegin() returns iterator to last element
D)
begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element

Correct Answer : Option (D) :   begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element


Explanation : Both begin() and cbegin() are used to access the first element of the vector. The function begin() returns an iterator to first element whereas cbegin() returns a constant iterator to first element.