[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.

# Commvault Written Test Qs.(C++ Programming) :: Objects and Classes - Discussion

9 / 40

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'

Show Explanation

Operator overloading can be defined as assigning new meaning to the overloaded operator. In our program, we overloaded '+' operator which gets called when two instances of type 'test' are added.

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