Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
private:
6.
int a, b;
7.
public:
8.
void test()
9.
{
10.
a = 100;
11.
b = 200;
12.
}
13.
friend int compute(sample e1);
14.
};
15.
int compute(sample e1)
16.
{
17.
return int(e1.a + e1.b) - 5;
18.
}
19.
int main()
20.
{
21.
sample e;
22.
e.test();
23.
cout
Options:
A .  100
B .  200
C .  300
D .  295
Answer: Option D

In this program, we are finding a value from the given function by using the friend for compute function.
Output:
$ g++ friend4.cpp
$ a.out
295



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers