Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class Box
4.
{
5.
double width;
6.
public:
7.
friend void printWidth( Box box );
8.
void setWidth( double wid );
9.
};
10.
void Box::setWidth( double wid )
11.
{
12.
width = wid;
13.
}
14.
void printWidth( Box box )
15.
{
16.
box.width = box.width * 2;
17.
cout
Options:
A .  40
B .  5
C .  10
D .  20
Answer: Option D

We are using the friend function for printwidth and multiplied the width value by 2, So we got the output as 20
Output:
$ g++ friend.cpp
$ a.out
20



Was this answer helpful ?

Submit Solution

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

Latest Videos

Latest Test Papers