C++ Friend Question:
Download Questions PDF

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

C++ Friend Interview Question
C++ Friend Interview Question

Answer:

a) function declaration
Explanation:
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.

Download C++ Friend Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

#include <iostream>
using namespace std;
class base
{
int val1, val2;
public:
int get()
{
val1 = 100;
val2 = 300;
}
friend float mean(base ob);
};
float mean(base ob)
{
return float(ob.val1 + ob.val2) / 2;
}
int main()
{
base obj;
obj.get();
cout << mean(obj);
return 0;
}
a) 200
b) 150
c) 100
d) 300
Pick out the correct statement.
a) A friend function may be a member of another class.
b) A friend function may not be a member of another class.
c) A friend function may or may not be a member of another class.
d) None of the mentioned