Menu
Popular Courses
Search
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 ?

Share this page with your friends!

Latest Videos

Chapter 1 - RMHP / OHP / OB & BP Part 1 : (14-02-2024) GPOE 2024
Cube & Cuboid Part 1 Reasoning (Hindi)
Data Interpretation (DI) Part1 Basic Concepts Reasoning (Hindi)
Counting Figures Part 1 Counting Of Straight Lines Reasoning (Hindi)
Direction Sense Test Part 1 Reasoning (Hindi)
Chapter 1 - GLOBAL STEEL SCENARIO & INDI Part 1 : (13-04-2024) ICA 2024
Real Numbers Part 7 Class 10 Maths

Latest Test Papers

Test paper 1 Reasoning & DI
Chapter 3.1 : INTRODUCTION GPOE/GPA 2024
Chapter 1.1 : INTRODUCTION GPOE/GPA 2024
Chapter 2.3 : COAL HANDLING PLANT - Set 1 GPOE/GPA 2024
Chapter 1.1 : Personnel Functions- An overview GFM 2024