C++ Programming Questions and Answers – Essential Operators

This section on online C++ test focuses 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 C++ 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: 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.
advertisement
advertisement

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

  1.     #include <iostream>
  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
View Answer

Answer: a
Explanation: 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:

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ g++ ess.cpp
$ a.out
a:4 b:7

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

advertisement
  1.     #include <iostream>
  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
View Answer

Answer: b
Explanation: 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:

advertisement
$ g++ ess1.cpp
$ a.out
7

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

  1.     #include <iostream>
  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
View Answer

Answer: b
Explanation: && 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
View Answer

Answer: b
Explanation: left to right is the associativity of add(+);.

8. What is the name of | operator?
a) sizeof
b) or
c) and
d) modulus
View Answer

Answer: b
Explanation: | 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
View Answer

Answer: b
Explanation: Scope resolution operator is having the highest precedence in c++.

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

  1.     #include <iostream>
  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
View Answer

Answer: a
Explanation: In this program, the value e is evaluated by precedence ad we got the output as 50.
Output:

$ g++ ess4.cpp
$ a.out
50

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.