CPP

CPP

Operator Functions has 9 Questions
Pick the other name of operator function.

function overloading
operator overloading
member overloading
None of the mentioned
Which of the following operators can't be overloaded?

::
+
?
[]
How to declare operator function?

operator operator sign
operator
operator sign
None of the mentioned
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 << c.x << "," << c.y;
  30.         return 0;
  31.     }

5, 5
7, 3
3, 7
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Integer 
  4.     {
  5.         int i;
  6.         public:
  7.         Integer(int ii) : i(ii) {}
  8.         const Integer
  9.         operator+(const Integer& rv) const 
  10.         {
  11.             cout << "operator+" << endl;
  12.             return Integer(i + rv.i);
  13.         }
  14.         Integer&
  15.         operator+=(const Integer& rv) 
  16.         {
  17.             cout << "operator+=" << endl;
  18.             i += rv.i;
  19.             return *this;
  20.         }
  21.     };
  22.     int main() 
  23.     {
  24.         int i = 1, j = 2, k = 3;
  25.         k += i + j;
  26.         Integer ii(1), jj(2), kk(3);
  27.         kk += ii + jj;
  28.     }

operator+ operator+=
operator+= operator+
operator+ operator+
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class myclass
  4.     {
  5.         public:
  6.         int i;
  7.         myclass *operator->()
  8.         {return this;}
  9.     };
  10.     int main()
  11.     {
  12.         myclass ob;
  13.         ob->i = 10; 
  14.         cout << ob.i << " " << ob->i;
  15.         return 0;
  16.     }

10 10
11 11
error
runtime error
Which of the following statements is NOT valid about operator overloading?

Only existing operators can be overloaded.
Overloaded operator must have at least one operand of its class type.
The overloaded operators follow the syntax rules of the original operator.
None of the mentioned
Operator overloading is

making c++ operator works with objects
giving new meaning to existing operator
making new operator
both a & b
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     ostream & operator<<(ostream & i, int n)
  4.     {
  5.         return i;
  6.     }
  7.     int main()
  8.     {
  9.         cout << 5 << endl;
  10.         cin.get();
  11.         return 0;
  12.     }

5
6
error
runtime error