Essential Operators(C++ Programming ) Questions and Answers
Question 1.
What is the output of this program?
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
50
60
70
90
Explanation:-
Answer: Option A. -> 50
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
Question 2.
Which operator is having the highest precedence in c++?
array subscript
Scope resolution operator
static_cast
dynamic_cast
Explanation:-
Answer: Option B. -> Scope resolution operator
None.
Question 3.
What is the name of | operator?
sizeof
or
and
modulus
Explanation:-
Answer: Option B. -> or
| operator is used to find the 'or' of given values.
Question 4.
What is the associativity of add(+);
right to left
left to right
both of these
None of the mentioned
Explanation:-
Answer: Option B. -> left to right
None.
Question 5.
What is the output of this program?
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
false
error
None of the mentioned
Explanation:-
Answer: Option B. -> false
&& is called as Logical AND operator, if there is no zero in the operand means, it will be true
Question 6.
What is the output of this program?
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
2
7
9
14
Explanation:-
Answer: Option B. -> 7
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
Question 7.
What are the essential operators in c++?
+
|
All of the mentioned
Explanation:-
Answer: Option D. -> All of the mentioned
None.
Question 8.
What is the output of this program?
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:4 b:7
a:10 b:4
a:4 b:10
None of the mentioned
Explanation:-
Answer: Option A. -> a:4 b:7
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
Question 9.
In which direction does the assignment operation will take place?
left to right
right to left
top to bottom
None of the mentioned
Explanation:-
Answer: Option B. -> right to left
In assignment operation, the flow of execution will be from right to left only.
Question 10.
Pick out the compound assignment statement.
a = a - 5
a = a / b
a -= 5
None of the mentioned
Explanation:-
Answer: Option C. -> a -= 5
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.