Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Example
    {
    private:
    int* K;
    int L;
    public:
    Example (int L);
    ~Example ();
    int& operator [] (int num);
    };
    int& Example::operator [] (int num)
    {
    return K[num];
    }
    Example::Example (int L)
    {
    K = new int [L];
    L = L;
    }
    Example::~Example ()
    {
    delete [] K;
    }
    int main ()
    {
    Example obj (10);
    obj [0] = 15;
    obj [1] = 10;
    obj [2] = 35;
    obj [3] = 30;
    for (int num = 0; num < 5; ++ num)
    cout << obj [num] <<" ";
    return 0;
    }
    1. 15 10 0 30 35
    2. 35 30 15 10 0
    3. 0 10 15 30 35
    4. 0 15 10 35 30
    5. 15 10 35 30 0
Correct Option: E

In this program, we are printing the array in the reverse order by using subscript operator.



Your comments will be displayed only after manual approval.