Quiz: Operators

To View Tricks: Login Required

Number of Questions: 15

Question: 6 -

What is the name of | operator?

Options:
  1. and

  2. modulus

  3. or

  4. sizeof

  5. Answer:

    or

    Solution:

    | operator is used to find the ‘or’ of given values.


Question: 7 -

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

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

    int a = 0;
    int b = 10;
    a = 2;
    b = 7;
    if (a && b) {
        cout << "true: " << endl;
    }
    else 
    {
        cout << "false: " << endl;
    }
    return 0;
}

Options:
  1. error

  2. 10

  3. false

  4. true

  5. Answer:

    false

    Solution:

    && is called as Logical AND operator, if there is no zero in the operand means, it will be true otherwise false.


Question: 8 -

What is the associativity of add(+); ?

Options:
  1. right to left

  2. left to right

  3. right to left & left to right

  4. top to bottom

  5. Answer:

    left to right

    Solution:

    left to right is the associativity of add(+);.


Question: 9 -

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

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

    int a, b, c;
    a = 2;
    b = 7;
    c = (a > b) ? a : b;
    cout << "c: " << c;

    return 0;
}

Options:
  1. 2

  2. 9

  3. 14

  4. 7

  5. Answer:

    7

    Solution:

    We are using the ternary operator to evaluate this expression. It will return first option, if first condition is true otherwise it will return second


Question: 10 -

Which operator is having the highest precedence in c++?

Options:
  1. Scope resolution operator

  2. array subscript

  3. static_cast

  4. dynamic_cast

  5. Answer:

    Scope resolution operator

    Solution:

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