Question
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
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
Answer: Option D
Was this answer helpful ?
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