Test Series - cpp

Test Number 71/102

Q: Which of the following syntax is used to convert any variable to its original type?
A. any_cast();
B. any_cast(variable_name);
C. (variable_name);
D. any_cast(variable_name);
Solution: The syntax used to convert the any variable to its original type is as follows:
any_cast(variable_name);
Q: Which header file is required to use any container?
A. 
B. 
C. 
D. 
Solution:  header file is required to use any container and its realted functions.
Q: Which exception is thrown if the typecasting is not done properly?
A. bad_type_cast
B. bad_any_cast
C. type_mismatched
D. bad_cast_mismatched
Solution: bad_any_cast exception is thrown when typecasting is not done properly by the user i.e. if any is storing int value and we are trying to cast it into a string then the program will throw bad_any_cast exception.
Q: What is the use of emplace() function?
A. Used to change the object any container is holding
B. Used to add more item to the any list
C. Used to empty any container value
D. Used to check the type of any variable
Solution: emplace() function is used to change the object contained in any container i.e destroying the present object and creating the new object for the value given by the user.
Q: What is the use of type() function in any container?
A. Used to destroys the contained object in any variable
B. Used to change the object any container is holding
C. Used to return the type information about the any container
D. Used to check whether a container is empty or not
Solution: type() function is used to check the type of data/value the container object is holding.
Q: What is the use of reset() function?
A. Used to destroys the contained object in any variable
B. Used to change the object any container is holding
C. Used to empty any container value
D. Used to check the type of any variable
Solution: reset() function is provided with any to destroy an object contained in any variable in case it is not needed.
Q: What is the use of has_value() function in any container?
A. Used to destroys the contained object in any variable
B. Used to change the object any container is holding
C. Used to return the type information about the any container
D. Used to check whether any container is empty or not
Solution: has_value() function is provided to check whether a given any container is empty or not.
Q: In how many ways we can handle errors in any class?
A. 1
B. 2
C. 3
D. 4
Solution: There are two ways of handling errors in any container first by using exceptions like bad_any_cast and second by returning the pointer.
Q: Which type of heap is implemented in STL heap?
A. max heap
B. min heap
C. middle heap
D. close heap
Solution: C++ STL-heap implements max heap i.e. the front of heap contains the maximum of all the elements in a range.
Q: Which function is used to construct heap from given sequence of numbers?
A. create_heap()
B. make_heap()
C. construct_heap()
D. start_heap()
Solution: C++ STL-heap container provides make_heap() function to convert a given range of number into heap.

You Have Score    /10