Multiple choice technology programming languages

The friend function of a class in C++ can access

  1. Private members of the class

  2. protected members of the class

  3. Both A and B

  4. None of the Above

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

Friend functions in C++ are granted special access to the private and protected members of the class they befriend. This breaks normal encapsulation rules when needed. Friend functions are commonly used for operator overloading and when external functions need deep class access. They do not access public members differently than any other function.