Multiple choice

What is the role of friend function in C++?

  1. Private and protected data members of the class can be accessed by defining the friend function.

  2. Only protected data members of the class can be accessed by defining the friend function.

  3. Only private data members of the class can be accessed by defining the friend function.

  4. Only public and protected data members of the class can be accessed by defining the friend function.

  5. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

We can access private and protected members both in the class by making the friend function of that class.