Test Series - cpp

Test Number 35/102

Q: What is the return type of the conversion operator?
A. void
B. int
C. float
D. no return type
Solution: Conversion operator doesn’t have any return type not even void.
Q: Why we use the “dynamic_cast” type conversion?
A. result of the type conversion is a valid
B. to be used in low memory
C. result of the type conversion is an invalid
D. it is used for storage
Solution: It is used to check that operators and operands are compatible after conversion.
Q: How many parameters does a conversion operator may take?
A. 0
B. 1
C. 2
D. as many as possible
Solution: 0 parameters does a conversion operator will take.
Q: How are types therein user-defined conversion?
A. 1
B. 2
C. 3
D. 4
Solution: There are two types of user-defined conversions. They are conversion by the constructor, Conversion functions.
Q: Pick out the correct syntax of operator conversion.
A. operator float()const
B. operator float()
C. operator const
D. operator const()
Solution: The syntax of operator conversion is operator float()const.
Q: Which rule will not affect the friend function?
A. private and protected members of a class cannot be accessed from outside
B. private and protected member can be accessed anywhere
C. protected member can be accessed anywhere
D. private member can be accessed anywhere
Solution: Friend is used to access private and protected members of a class from outside the same class.
Q: Which keyword is used to declare the friend function?
A. firend
B. friend
C. classfriend
D. myfriend
Solution: friend keyword is used to declare a friend function in C++.
Q: What is the syntax of friend function?
A. friend class1 Class2;
B. friend class;
C. friend class
D. friend class()
Solution: In option a, the class2 is the friend of class1 and it can access all the private and protected members of class1.
Q: Pick out the correct statement.
A. A friend function may be a member of another class
B. A friend function may not be a member of another class
C. A friend function may or may not be a member of another class
D. None of the mentioned
Solution: A friend function may or may not be a member of another class is the correct statement.
Q: Where does keyword ‘friend’ should be placed?
A. function declaration
B. function definition
C. main function
D. block function
Solution: The keyword friend is placed only in the function declaration of the friend function and not in the function definition because it is used toaccess the member of a class.

You Have Score    /10