Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include <iostream&f=gt;
    using namespace std;
    class Num
    {
    private:
    int Values[15];
    public:
    int& operator[] (const int Val);
    };
    int& Num::operator[](const int Val)
    {
    return Values[Val];
    }
    int main()
    {
    Num Object;
    Object[10] = 6;
    cout << Object[10];
    return 0;
    }
    1. 15
    2. 10
    3. 6
    4. Compilation Error
    5. None of these
Correct Option: C

In this program, We are getting the values and returning it by overloading the subscript operator.



Your comments will be displayed only after manual approval.