C++ Friend Functions MCQ (MULTIPLE CHOICE QUESTIONS)

We have already covered C++ Functions questions in the last set of MCQs. There, we have discussed some good questions. This set of MCQ(multiple choice questions focuses) on the C++ Friend Functions questions.

You should practice these interview questions to improve C++ programming skills needed for various interviews (like company interview, campus interview, walk-in interview), entrance exams, placements and other competitive exams. All the questions in this particular section are based on only “C++ Friend Functions MCQ“.

Instructions to be followed:-

  1. Read all the questions carefully.
  2. Out of the 4 given options for each questions, only ONE option will be correct.
  3. Choose the appropriate option.
  4. After attempting all the questions, click on “Finish” button to check the score.
  5. Share your result on social media handles available.

If you are not satisfied with your result or wants to attempt the Quiz again, don’t worry, you can try it again at the end (by refreshing the page). You can use Previous and Next button to switch to a different set of questions.

C++ FRIEND Functions MCQ
C++ FRIEND FUNCTIONS MCQ

C++ MCQ | FRIEND FUNCTIONS

Now, start attempting the quiz.

C++ Friend Functions MCQ Questions

1. Which keyword is used to represent a friend function?

a) friend
b) Friend
c) friend_func
d) Friend_func

Answer: a) friend

2. Which rule will not affect the friend function?

a) private and protected member can be accessed anywhere
b) private and protected members of a class cannot be accessed from outside
c) private member can be accessed anywhere
d) protected member can be accessed anywhere

Answer: b)

Explanation: Friend is used to access private and protected members of a class from outside the same class

3. What is a friend function in C++?

a) A function which is not allowed to access any member of any class
b) A function which is allowed to access public and protected members of a class
c) A function which can access all the private, protected and public members of a class
d) A function which is allowed to access only public members of a class

Answer: c)

Explanation: In C++, a friend function can access all the private, protected and public members of a class.

4. What is the syntax of friend function?

a) friend class;
b) friend class
c) friend class1 Class2;
d) friend class()

Answer: c) friend class1 Class2;

Explanation: In option c, the class2 is the friend of class1 and it can access all the private and protected members of class1.

5. Where does keyword ‘friend’ should be placed?

a) function declaration
b) block function
c) function definition
d) main function

Answer: a) function declaration

6. A friend function can be

a) A global function
b) None of these
c) Both A and D
d) A method of another class

Answer: c) Both A and D

7. If class A is a friend of B, then B doesn’t become a friend of A automatically.

a) True
b) False
c) Can’t say
d) Can be true and false

Answer: a) True

Explanation: Friendship is not mutual. If class A is a friend of B, then B doesn’t become a friend of A automatically.

8. Pick out the correct statement.

a) A friend function may or may not be a member of another class
b) A friend function may be a member of another class
c) None of the mentioned
d) A friend function may not be a member of another class

Answer: a) A friend function may or may not be a member of another class

9. Which of the following is correct about friend functions?

a) Friend functions use the dot operator to access members of a class using class objects
b) Friend cannot access the members of the class directly
c) Friend functions can be private or public
d) All of the mentioned

Answer: d) All of the mentioned

10. A friend class can access ____________________ members of other class in which it is declared as friend.

a) public
b) private
c) protected
d) Both B and C

Answer: d)

Explanation: A friend class can access private and protected members of other class in which it is declared as friend.

11. Pick the correct statement.

a) Friend functions are in the scope of a class
b) Friend functions can be called using class objects
c) Friend functions can be invoked as a normal function
d) Friend functions can access only protected members not the private members

Answer: c)

Explanation: Friend functions are not in the scope of a class and hence cannot be called through a class object. A friend function can access all types of members of the class. They can be invoked as a normal function.

12. A friend function declaration appears ______

a) in the header of the friend function outside the class
b) inside the class declaration to which it is a friend
c) as a separate declaration inside main()
d) anywhere prior to the function invocation

Answer: b)

13. If a function is friend of a class, which one of the following is wrong?

a) A function can only be declared a friend by a class itself.
b) Friend functions are not members of a class, they are associated with it.
c) Friend functions are members of a class.
d) It can have access to all members of the class, even private ones.

Answer: c)

Explanation: Friend of the class can be member of some other class but Friend functions are not the members of a particular class.

14. Which one of the following is correct, when a class grants friend status to another class?

a) The member functions of the class generating friendship can access the members of the friend class.
b) All member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship.
c) Class friendship is reciprocal to each other.
d) There is no such concept.

Answer: b)

Explanation:

  • When a class grants friend status to another class then all member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship.
  • The member functions of the class generating friendship can access the members of the friend class. Incorrect statement.
  • Class friendship is not reciprocal to each other.
So, option (B) is correct.

15. A friend function declaration:

a) gives non-member functions access to hidden class members
b) is another term for an overloaded function within a class
c) is any function created for you by the compiler (such as a default constructor)
d) is any function outside the class with the same name as a function in the class

Answer: a)


<< Prev- C++ MCQs : Functions

>> Next- C++ MCQ : Pointer to Functions


Wants to learn more about C++ Programming? If yes, then don’t forget to explore all the topics of C++ programming. Here, is the complete set of Multiple Choice Questions and Answers. You should learn all the questions available there. These questions are very helpful for the preparation of placements, Competitive Exams and University level exams.

Do practice of HTML questions :- Multiple choice questions on HTML

Do practice of C programming :- Multiple choice questions on C programming

Want backlinks to your website? If yes, then follow this article and get to know in very easy way. How You Can Create High Quality Backlinks In 2021?

The above question set contains all the correct answers. But in any case, you find any typographical, grammatical or any other error in our site then kindly inform us. Don’t forget to provide the appropriate URL along with error description. So that we can easily correct it.

Thanks in advance.

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

Leave a Comment

Your email address will not be published. Required fields are marked *