What is a friend function in C++?
19 views
- A function that is declared inside a class.
- A function that can access the private and protected members of a class. (Correct Answer)
- A function that is used to overload the << operator.
- A function that returns a reference to an object.
Explanation
Correct answer: b) A function that can access the private and protected members of a class.
Explanation: A friend function in C++ is a non-member function that is declared as a friend of a class. This allows the function to access the private and protected members of the class, even though it is not a member of the class itself.