[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C++ Programming :: Objects and Classes - Discussion

Home > C++ Programming > Objects and Classes > MCQs Questions Discussion

11 / 41

What is the output of the C++ program?

#include <iostream>
using namespace std;
 
class test { 
float x,  y; 
public:
test(float a = 1.0,  float b = 2.0)
{
x = a;
y = b;
}

test operator + (test & obj) {
return test(this->x + obj.x,  y + obj.y);
}

operator float () {
return  (x + y) ;
}
};

int main () {
test obj1(1.23, 4.56), obj2;
obj2  = obj1 + obj2;
cout << obj2;
return 0;
}

A8.79

B5.79

C3

DCompilation error: binary '<<': no operator found which takes a right-hand operand of type 'test'

Answer: Option (Login/Signup)

Show Explanation

operator float () is a conversion operator which converts type 'test' to float. 

Asked In :: Commvault Sopra Steria

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here