Operators


  1. Which concepts does the Pre Increment use?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    call by reference


  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. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

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



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    const int SIZE = 15;
    class Example
    {
    private:
    int array[SIZE];
    public:
    Example()
    {
    register int k;
    for (k = 0; k < SIZE; k++)
    {
    array[k] = k;
    }
    }
    int &operator[](int k)
    {
    if (k > SIZE)
    {
    cout << " Index out of bounds" << endl;

    return array[0];
    }
    return array[k];
    }
    };
    int main()
    {
    Example Object;
    cout << Object[10];
    cout << Object[20];
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We are returning the elements in the specified array location and if it is out of bound means it will return the first element.


  1. Pick out the correct statement.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    subscript operator has a higher precedence than the assignment operator.



  1. How many arguments will the subscript operator will take for overloading?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The subscript operator overload takes only one argument, but it can be of any type.