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
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
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
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.
4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) a:4 b:6
View Answer
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:
$ g++ ess.cpp $ a.out a:4 b:7
5. 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;
return 0;
}
a) 2
b) 7
c) 9
d) 14
View Answer
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:
$ g++ ess1.cpp $ a.out 7
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 10;
if ( a && b )
{
cout << "true"<< endl ;
}
else
{
cout << "false"<< endl ;
}
return 0;
}
a) true
b) false
c) error
d) 10
View Answer
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
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
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
Explanation: Scope resolution operator is having the highest precedence in c++.
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = a + b * c / d;
cout << e << endl ;
return 0;
}
a) 50
b) 60
c) 70
d) 90
View Answer
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.
- Apply for Computer Science Internship
- Check Computer Science Books
- Apply for C++ Internship
- Practice Computer Science MCQs
- Check Programming Books