Test Series - cpp

Test Number 91/102

Q: What are functors in C++?
A. Objects of a class which are treated as functions
B. Objects that are used to call the function of other classes
C. Functions that are called using pointer objects
D. Functions that are called only once in a program
Solution: Functors are objects of a class that are treated like function i.e. they can also be used as function calls.
Q: Which of the following operators are overloaded for functors?
A. []
B. ()
C. <<
D. >>
Solution: () operator is overloaded to use functor property in a C++ program because this is the only operator used for a function call.
Q: What is the correct function prototype of () operator overloading?
A. return_type operator(arguments)();
B. return_type operator(arguments);
C. return_type operator()(arguments);
D. return_type operator(Class_name)(arguments);
Solution: The correct syntax of overloading a () operator in a class is as follows:
return_type operator()(arguments){}
Q: Which of the following is correct about Functors?
A. Functors should not be declared outside the main function
B. Overloaded operator () function is not a member of the class
C. Functors should be declared global
D. Functors have a state
Solution: Functors are objects of a class which also have other members and member functions which can be used to save states of that functors hence functors have a state. Functors can be declared anywhere in a program.
Q: Which of te following is a built-in example of functors in C++?
A. mltiplication f(a1, a2);
B. add f(a1, a2);
C. subtract f(a1, a2);
D. plus f(a1, a2);
Solution: plus f(a1, a2); is one of the correct in-built functor available.
Q: Which of the following header file is required to use in-bulit functors of C++?
A. 
B. 
C. 
D. 
Solution:  header file is required to use the fuctionality of in-built functors provided by C++.
Q: What are unary functors?
A. Functors that accepts only one parameter
B. Functors that accepts two parameters
C. Functors that accepts more than one parameters
D. Functors that accepts other than a specific type of parameter
Solution: Unary functors are those which accepts only one argument as a parameter in a functor.
Q: What are binary functors?
A. Functors that accepts only one parameter
B. Functors that accepts more than one parameters
C. Functors that accepts two parameters
D. Functors that accepts other than a specific type of parameter
Solution: Binary functors are those which accepts two arguments as a parameter in a functor.
Q: How many ways are there to use functors?
A. 1
B. 2
C. 3
D. 4
Solution: There are two ways of using functors one like function calls and other like normal class objects.
Q: Which of the following is an arithmetic unary functor?
A. logical_not f;
B. logical_and f;
C. logical_or f;
D. negate f;
Solution: logical_and and logical_or requires two arguments to act upon whereas negate and logical_not requires only one argument but logical_not produces only logical results, therefore, will not work on arithmetic values whereas negate works with all types of values.

You Have Score    /10