Test Series - cpp

Test Number 69/102

Q: How many list sequence containers are provided by STL?
A. 1
B. 2
C. 3
D. 4
Solution: There are two list sequence containers are provided by STL namely forward_list and list.
Q: Which type of list a Forward_list sequence container implements?
A. Singly Linked List
B. Doubly Linked List
C. Both type of list
D. A simple sequence of array
Solution: Forward_list sequence container implements a Singly Linked List.
Q: Which type of list a List sequence container implements?
A. Singly Linked List
B. Doubly Linked List
C. Both type of list
D. A simple sequence of array
Solution: List sequence container implements Doubly Linked List.
Q: Which of the following header file is required for forwawrd_list?
A. 
B. 
C. 
D. 
Solution: One needs to implement  header file to use forward_list in a program.
Q: Which of the following(s) is/are the correct way of assigning values to a forward_list f?
A. f.assign({1,2,3,4,5})
B. f.assign(10,5)
C. both f.assign({1,2,3,4,5}) and f.assign(10,5)
D. f.assign(1,1,1,1)
Solution: Both f.assign({1,2,3,4,5}) and f.assign(10,5) are correct way of assigning values to a forward_list. The first assignment initializes the list with the elements 1,2,3,4 and 5 whereas the second assignment initializes the list 10 elements with value 5 i.e. 5 10 times.
Q: How the list differs from vectors?
A. Vector is contiguous whereas List is non-contiguous
B. Insertion in the list takes constant time whereas it is not constant in vectors
C. There is no capacity defined for list
D. All of the mentioned
Solution: List is non-contiguous that means elements of a list are not the contiguous manner in memory. Insertion in a list is constant for because we are not increasing the size of the list anywhere which was the case of a vector. Vectors have a capacity defined whereas there is no such capacity defined for Lists.
Q: What is the syntax of declaraing a forward_list?
A. forward_list f;
B. forward_list f;
C. forward_list f;
D. forward_list f;
Solution: forward_list f; is the correct syntax of declaring a forward-list.
Q: What is a pair?
A. Container consisting of two data elements of the same type
B. Container consisting of two data elements of different type
C. Container consisting of one header and two data elements of the same type
D. Container consisting of two data elements can have the same or different type
Solution: Pair is a container defined in STL which consist of two elements which can be of same or different types.
Q: Which header file is required to use pair container in your program?
A. 
B. 
C. 
D. 
Solution: Pair container is defined under the header file  therefore one should include header before using pair container.
Q: Which of the following is the correct syntax of using pair p?
A. pair p;
B. pair p ;
C. pair [type,type] p;
D. pair p [type,type];
Solution: A pair is declared using the this syntax pair  identifier.

You Have Score    /10