Test Series - cpp

Test Number 38/102

Q: subscript operator is used to access which elements?
A. string
B. char
C. array
D. float
Solution: To access any element of an array we use following syntax array[i], where i is called subscript representing the ith element of an array, whereas no such cases in char and strings.
Q: How many arguments will the subscript operator will take for overloading?
A. 1
B. 2
C. 0
D. as many as possible
Solution: The subscript operator overload takes only one argument, but it can be of any type.
Q: Pick out the correct statement.
A. subscript operator has a higher precedence than the assignment operator
B. subscript operator has a lower precedence than the assignment operator
C. subscript operator is used with string elements
D. subscript operator is used with char elements
Solution: Subscription operator has more precedence otherwise if that is not the case then the statement var = arr[i] will be meaningless and will have no effect.
Q: What do we need to do to pointer for overloading the subscript operator?
A. reference pointer
B. dereference pointer
C. store it in heap
D. memory locator
Solution: If you have a pointer to an object of some class type that overloads the subscript operator, you have to dereference that pointer in order to free the memory.
Q: What do we need to use when we have multiple subscripts?
A. operator()
B. operator[]
C. operator
D. operator<>
Solution: The reason is that operator[] always takes exactly one parameter, but operator() can take any number of parameters.
Q: What is the use of function call operator?
A. overloading the methods
B. overloading the objects
C. overloading the parameters
D. overloading the string
Solution: Overloading the objects is the use of function call operator.
Q: Pick out the correct statement.
A. virtual functions does not give the ability to write a templated function
B. virtual functions does not give the ability to rewrite a templated function
C. virtual functions does give the ability to write a templated function
D. virtual functions does not give the ability to rewrite a simple function
Solution: Virtual functions does not give the ability to write a templated function.
Q: What will happen when the function call operator is overloaded?
A. It will not modify the functions
B. It will modify the functions
C. It will modify the object
D. It will modify the operator to be interpreted
Solution: It will modifies how the operator is to be interpreted when applied to objects of a given type.
Q: In which form does the function call operator can be overloaded?
A. static member function
B. non-static member function
C. dynamis_cast
D. static_cast
Solution: In non-static member function, the function call operator can be overloaded.
Q: What is the use of functor?
A. It makes the object “callable” like a function
B. It makes the class “callable” like a function
C. It makes the attribute “callable” like a function
D. It makes the argument “callable” like a function
Solution: functor makes the object “callable” like a function.

You Have Score    /10