In C++, by declaring function as friend function

2025

In C++, by declaring function as friend function

  1. A.

    The function can use the private and protected members of the class

  2. B.

    The function is in the scope of the class

  3. C.

    The function must be invoked in an object

  4. D.

    None of the above

Attempted by 49 students.

Show answer & explanation

Correct answer: A

A friend function in C++ is declared outside a class but granted access to its private and protected members. This allows non-member functions to interact directly with internal class data without being a member function themselves.

Explore the full course: Mppsc Assistant Professor