adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream> 
    using namespace std;
    class A
    {
        public:
        int x;
        A(int n = 0) : x(n) {};
        int& operator[](int n)
        {
             cout << "0" ;
             return x;
        }
        int operator[](int n) const
        {
             cout << "1" ;
             return x;
        }
     };
    void foo(const A& a)
    {
        int z = a[2];
    }
    int main()
    {
        A a(7);
        a[3]  = 8;
        int z = a[2];
        foo(a);
        return 0;
    }

a.

110

b.

111

c.

011

d.

001

Answer: (d).001

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?