250+ TOP MCQs on Essential Operators and Answers

This section on online C++ test on “Essential Operators”. One shall practice these test questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our online C++ test questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of online C++ test questions on “Essential Operators” along with answers, explanations and/or solutions:

1. What are the essential operators in c++?
a) +
b) |
c) <=
d) All of the mentioned
Answer: d
Clarification: Essential operators in c++ are +, |, <=.

2. In which direction does the assignment operation will take place?
a) left to right
b) right to left
c) top to bottom
d) bottom to top
Answer: b
Clarification: In assignment operation, the flow of execution will be from right to left only.

3. Pick out the compound assignment statement.
a) a = a – 5
b) a = a / b
c) a -= 5
d) a = a + 5
Answer: c
Clarification: When we want to modify the value of a variable by performing an operation on the value currently stored, We will use compound assignment statement. In this option, a -=5 is equal to a = a-5.

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

  1.     #include 
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int a, b;         
  6.         a = 10;           
  7.         b = 4;            
  8.         a = b;           
  9.         b = 7;           
  10.         cout << "a:";
  11.         cout << a;
  12.         cout << " b:";
  13.         cout << b;
  14.         return 0;
  15.     }

a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) a:4 b:6
Answer: a
Clarification: In this program, we are reassigning the values of a and b because of this we got the output as a:4 b:7
Output:

$ g++ ess.cpp
$ a.out
a:4 b:7

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

  1.     #include 
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int a, b, c;
  6.         a = 2;
  7.         b = 7;
  8.         c = (a > b) ? a : b;
  9.         cout << c;
  10.         return 0;
  11.     }

a) 2
b) 7
c) 9
d) 14
Answer: b
Clarification: 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
Output:

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

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 0;
  6.         int b = 10;
  7.         if ( a && b )
  8.         {
  9.             cout << "true"<< endl ;
  10.         }
  11.         else
  12.         {
  13.             cout << "false"<< endl ;
  14.         }
  15.         return 0;
  16.     }

a) true
b) false
c) error
d) 10
Answer: b
Clarification: && is called as Logical AND operator, if there is no zero in the operand means, it will be true otherwise false.
Output:

$ g++ ess2.cpp
$ a.out
false

7. What is the associativity of add(+);?
a) right to left
b) left to right
c) right to left & left to right
d) top to bottom
Answer: b
Clarification: left to right is the associativity of add(+);.

8. What is the name of | operator?
a) sizeof
b) or
c) and
d) modulus
Answer: b
Clarification: | operator is used to find the ‘or’ of given values.

9. Which operator is having the highest precedence in c++?
a) array subscript
b) Scope resolution operator
c) static_cast
d) dynamic_cast
Answer: b
Clarification: Scope resolution operator is having the highest precedence in c++.

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

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 20;
  6.         int b = 10;
  7.         int c = 15;
  8.         int d = 5;
  9.         int e;
  10.         e = a + b * c / d;
  11.         cout << e << endl ;
  12.         return 0;
  13.     }

a) 50
b) 60
c) 70
d) 90
Answer: a
Clarification: In this program, the value e is evaluated by precedence ad we got the output as 50.
Output:

$ g++ ess4.cpp
$ a.out
50
  250+ TOP MCQs on Vector and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top