Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
public:
6.
int x, y;
7.
sample() {};
8.
sample(int, int);
9.
sample operator + (sample);
10.
};
11.
sample::sample (int a, int b)
12.
{
13.
x = a;
14.
y = b;
15.
}
16.
sample sample::operator+ (sample param)
17.
{
18.
sample temp;
19.
temp.x = x + param.x;
20.
temp.y = y + param.y;
21.
return (temp);
22.
}
23.
int main ()
24.
{
25.
sample a (4,1);
26.
sample b (3,2);
27.
sample c;
28.
c = a + b;
29.
cout
Options:
A .  5, 5
B .  7, 3
C .  3, 7
D .  None of the mentioned
Answer: Option B

In this program, we are adding the first number of a with first number
of b by using opertor

function and also we are adding second number by
this method also.
Output:
$ g++ oper.cpp
$ a.out
7, 3



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers