adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    const int SIZE = 10;
    class safe
    {
        private:
        int arr[SIZE];
        public:
        safe()
        {
            register int i;
            for (i = 0; i < SIZE; i++)
            {
                arr[i] = i;
            }
        }
        int &operator[](int i)
        {
            if (i > SIZE)
            {
                cout << "Index out of bounds" <<endl;
                return arr[0];
            }
            return arr[i];
        }
    };
    int main()
    {
        safe A;
        cout << A[5];
        cout  << A[12];
        return 0;
    }

a.

5Index out of bounds 0

b.

40

c.

50

d.

51

Answer: (a).5Index out of bounds 0

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?