Operators And Statements(Engineering > Computer Science And Engineering > C++ Language ) Questions and Answers
Question 1. Which operator is having right to left associativity in the following?
Array subscripting
Function call
Addition and subtraction
Type cast
Explanation:-
Answer: Option D. -> Type cast
Type cast
Question 2. What is the use of dynamic_cast operator?
it converts virtual base class to derived class
it converts virtual base object to derived objeccts
it will convert the operator based on precedence
None of the mentioned
Explanation:-
Answer: Option A. -> it converts virtual base class to derived class
Because the dynamic_cast operator is used to convert from base class to derived class.
Question 3. Which operator is having the highest precedence?
postfix
unary
shift
equality
Explanation:-
Answer: Option A. -> postfix
The operator which is having highest precedence is postfix and lowest is equality.
Question 4.
What is the output of this program?
#include
using namespace std;
int main()
{
int a;
a = 5 + 3 * 5;
cout
35
20
25
30
Explanation:-
Answer: Option B. -> 20
Because the * operator is having highest precedence, So it is executed first and then the + operator will be executed.
Question 5. What is this operator called ?: ?
conditional
relational
casting operator
none of the mentioned
Explanation:-
Answer: Option A. -> conditional
In this operator, if the condition is true means, it will return the first operator, otherwise second operator.
Question 6.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 6, c, d;
c = a, b;
d = (a, b);
cout
5 6
6 5
6 7
none of the mentioned
Explanation:-
Answer: Option A. -> 5 6
It is a separtor here.In c,the value a is stored in c and in d the value b is stored in d because of the bracket.
Question 7.
What is the output of this program?
#include < iostream >
using namespace std;
main()
{
double a = 21.09399;
float b = 10.20;
int c ,d;
8. c = (int) a;
d = (int) b;
cout
20 10
10 21
21 10
none of the mentioned
Explanation:-
Answer: Option C. -> 21 10
In this program, we are casting the operator to integer, So it is printing as 21 and 10
Question 8. What is the output of this program?#include < iostream >using namespace std;int main (){int x, y;x = 5;y = ++x * ++x;cout
749736
736749
367497
none of the mentioned
Explanation:-
Answer: Option A. -> 749736
Because of the precedence the pre-increment and post increment operator, we got the output as 749736.
Question 9.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 6, c;
c = (a > b) ? a : b;
cout
6
5
4
7
Explanation:-
Answer: Option A. -> 6
Here the condition is false on conditional operator, so the b value is assigned to c
Question 10.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout
1000
11
1010
1001
Explanation:-
Answer: Option C. -> 1010
j starts with the value 10. j is then incremented to 11. Next, j is added to 100. Finally, j (still containing 11) is added to 999 which yields the result 1010.