ExamVeda
Login
Home
Classes and Objects in C plus plus
?

What will be the output of the following C++ code?
#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;
}

Answer & Solution
Correct Answer: Option A
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.