Operator Functions

Q.

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

Answer : Option A

Explanation :

In this program, -> operator is used to describe the member of the class and so we are getting this output.
Output:
$ g++ char4.cpp
$ a.out
10 10