Vidyalelo
C++ Programming · Q159

Classes and Objects in C++

Programming · C++ Programming · question 159

Q159

What will be the output of the following C++ code? #include #include using namespace std; class complex int i; int j; public: complex() complex(int a, int b) i = a; j = b; complex operator+(complex c) complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; void operator+(complex c) complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; temp.show_poss(); void show() cout<<"Complex Number: "<<i<<" + i"<<j<<endl; void show_poss() cout<<"Your result after addition will be: "<<i<<" + i"<<j<<endl; ; int main(int argc, char const *argv[]) complex c1(1,2); complex c2(3,4); c1 + c2; return 0;

A.
Complex Number: 4 + i6
B.
Complex Number: 2 + i2
C.
Error
Answer
D.
Segmentation fault

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board