Quiz: Operators

To View Tricks: Login Required

Number of Questions: 15

Question: 11 -

What is this operator called "?:" ?

Options:
  1. relational

  2. unrelational

  3. casting operator

  4. conditional

  5. Answer:

    conditional

    Solution:

    In this operator, if the condition is true means, it will return the first operator, otherwise second operator.


Question: 12 -

What is the use of dynamic_cast operator?

Options:
  1. it will convert the operator based on precedence

  2. it converts the virtual base object to derived class

  3. it converts virtual base class to derived class

  4. it converts the virtual base object to derived objects

  5. Answer:

    it converts virtual base class to derived class

    Solution:

    Because the dynamic_cast operator is used to convert from base class to derived class.


Question: 13 -

What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {

    int a = 5, b = 6, c;
    c = (a > b) ? a : b;
    cout << c;

    return 0;
}

Options:
  1. 6

  2. 4

  3. 7

  4. 5

  5. Answer:

    6

    Solution:

    Here the condition is false on conditional operator, so the b value is assigned to c.


Question: 14 -

What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {

    int a = 20, b = 10, c = 15, d = 5;
    int e;
    e = a + b * c / d;
    cout << e << endl;

    return 0;
}

Options:
  1. 50

  2. 80

  3. 70

  4. 60

  5. Answer:

    60

    Solution:

    Scope resolution operator is having the highest precedence in c++.


Question: 15 -

Which operator is having the highest precedence?

Options:
  1. equality

  2. unary

  3. shift

  4. postfix

  5. Answer:

    equality

    Solution:

    The operator which is having the highest precedence is postfix and lowest is equality.