1. What are the essential operators in c++?
A. +
B. |
C. <=
D. All of the mentioned
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
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
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.
4. What will be the output of the following C++ code?
#include
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
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
5. What will be the output of the following C++ code?
#include
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
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
6. What will be the output of the following C++ code?
#include
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
Answer: B
Explanation:
&& is called as Logical AND operator, if there is no zero in the operand means, it will be true otherwise 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
Explanation:
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
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
Answer: B
Explanation:
Scope resolution operator is having the highest precedence in c++.
10. What will be the output of the following C++ code?
#include
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
Answer: A
Explanation:
In this program, the value e is evaluated by precedence ad we got the output as 50.