Question:

Which of the following is the correct way to declare a friend function in a class?

Show Hint

Where must the friend keyword sit, and does an access label like public matter for friendship?
Updated On: Jul 2, 2026
  • void friend display();
  • public: friend void display();
  • friend void display();
  • friend class display;
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: A friend function is declared inside the class with the keyword friend placed first, followed by the normal function signature.

Step 2: The correct form is:
 friend void display();
Here friend comes before the return type void and the function name.

Step 3: Check the wrong options. Option A writes void friend display(), which puts the keyword in the wrong place and is invalid syntax. Option D uses friend class display, which declares a friend class, not a friend function.

Step 4: Option B, public: friend void display(), is a common trap. Friendship is not affected by access labels, so adding public: is pointless and not the standard declaration. The clean, standard declaration is option C.

Answer: option C.
Was this answer helpful?
0
0