Operators


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    const int limit = 3;
    class arrayExample
    {
    private:
    int array[limit];
    public:
    int& operator [](int num)
    {
    if (num == limit - 2)
    {
    int temp;
    for (int k = 0; k < limit; k++)
    {
    if (array[num + 2] > array[num])
    {
    temp = array[num];
    array[num] = array[num + 2];
    array[num + 2] = temp;
    }
    }
    }
    return array[num];
    }
    };
    int main()
    {
    arrayExample sa1;
    for(int L = 0; L < limit; L++)
    sa1[L] = L*10;
    for(int L = 0; L < limit; L++)
    {
    int temp = sa1[L];
    cout << "Element of " << L << " is " << temp << endl;

    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, we are returning the array element by the multiple of 5.


  1. Pick out the correct statement











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Because Pre Increment take one-byte instruction & post increment takes two-byte instruction.



  1. What is the output of this program?
    #include <iostream> 
    using namespace std;
    int main()
    {
    int num1 = 7;
    int num2 = 4;
    int num3 = 6;
    num1 = num2++;
    num2 = --num3;
    cout << num1 <<" " << num2 <<" " << num3;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We are pre increment and post incrementing the operands and saving it.


  1. What is the output of this program?
    #include <iostream>  
    using namespace std;
    int main()
    {
    int num1 = 7, num2 = 3, Res;
    num1 = ++num1;
    num2 = --num2;
    Res = num1 + ++num1;
    cout << Res;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In this program, we are adding the num1 value after pre incrementing two times.



  1. What is the output of this program?
    #include <iostream>  
    using namespace std;
    int main()
    {
    int num1 = 7, num2 = 3, Res;
    num1 = ++num1;
    num2 = --num2;
    Res = num1 + ++num1;
    cout << Res;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In this program, we are adding the num1 value after pre incrementing two times.