Operator Functions

1

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.
    }
A. 5
B. 6
C. error
D. runtime error

2

Operator overloading is

A. making c++ operator works with objects
B. giving new meaning to existing operator
C. making new operator
D. both a & b

3

Which of the following statements is NOT valid about operator overloading?

A. Only existing operators can be overloaded.
B. Overloaded operator must have at least one operand of its class type.
C. The overloaded operators follow the syntax rules of the original operator.
D. None of the mentioned

4

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.
    }
A. 10 10
B. 11 11
C. error
D. runtime error

5

1.
    #include 
2.
    using namespace std;
3.
    class Integer 
4.
    {
5.
        int i;
.
        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.
    }

a) operator+

operator+=

b) operator+=

operator+

c) operator+

operator+

d) None of the mentioned