1. List the advantages of using friend classes?

There are situations when private data members need to be accessed and used by 2 classes simultaneously. In these kind of situations we can introduce friend functions which have an access to the private data members of both the classes. Friend functions need to be declared as 'friend' in both the classes. They need not be members of either of these classes.

2. What are the C++ friend classes? Explain its uses with an example?

A friend class and all its member functions have access to all the private members defined within other class.

#include <iostream>
using namespace std;
class Numbers
int a;
int b;
Numbers(int i, int j)
a = i;
b = j;
friend class Average;

class Average
int average(Numbers x);

int Average:: average(Numbers x)
return ((x.a + x.b)/2);

int main()
Numbers ob(23, 67);
Average avg;
cout<<"The average of the numbers is: "<<avg.average(ob);
return 0;

Note the friend class member function average is passed the object of Numbers class as parameter.

3. List the characteristics of friend functions?

Friend functions are not a part of the class and are external. This function is a "Friend" of a class. This is to say, it has special privileges to access to the class's private and protected members.

4. What is the friend class in C++?

When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend class member methods. Friendship is one way only, which means if A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.

6. Where does keyword 'friend' should be placed?
a) function declaration
b) function definition
c) main function
d) None of the mentioned

a) function declaration
The keyword friend is placed only in the function declaration of the friend function and not in the function definition because it is used toaccess the member of a class.