C++ Programming MCQ Question– Operators

C++ language interview questions and answers focuses on “Operators”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in 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 C++ language interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

C++ language interview questions on “Operators” along with answers, explanations and/or solutions:

Q 1. Which operator is having the right to left associativity in the following?
A. Array subscripting
B. Function call
C. Addition and subtraction
D. Type cast

Show Answer Answer:-D. Type cast
Explanation There are many rights to left associativity operators in C++, which means they are evaluation is done from right to left. Type Cast is one of them.

Q 2. Which operator is having the highest precedence?
A. postfix
B. unary
C. shift
D. equality

Show Answer Answer:-A. postfix
Explanation The operator which is having the highest precedence is postfix and lowest is equality.

Q 3. What is this operator called ?:?
A. casting operator
B. relational
C. conditional
D. unrelational

Show Answer Answer:-C. conditional
Explanation In this operator, if the condition is true means, it will return the first operator, otherwise second operator.

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

#include <iostream>

using namespace std;

int main()

{

int a;

a = 5 + 3 * 5;

cout << a;

return 0;

}

A. 20
B. 25
C. 30
D. 35

Show Answer Answer:-A. 20
Explanation Because the * operator is having highest precedence, So it is executed first and then the + operator will be executed. Output: $ g++ op1.cpp $ a.out 20

Q 5. What is the use of dynamic_cast operator?
A. it converts virtual base class to derived class
B. it converts the virtual base object to derived objects
C. it will convert the operator based on precedence
D. it converts the virtual base object to derived class

Show Answer Answer:-A. it converts virtual base class to derived class
Explanation Because the dynamic_cast operator is used to convert from base class to derived class.

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

#include <iostream>

using namespace std;

int main()

{

int a = 5, b = 6, c, d;

c = a, b;

d = (a, b);

cout << c << ‘ ‘ << d;

return 0;

}

A. 5  6
B. 6  5
C. 6  7
D. 6  8

Show Answer Answer:-A. 5  6
Explanation It is a separator here. In C, the value a is stored in c and in d the value b is stored in d because of the bracket. Output: $ g++ op3.cpp $ a.out 5 6

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

#include <iostream>

using namespace std;

int main()

{

int i, j;

j = 10;

i = (j++, j + 100, 999 + j);

cout << i;

return 0;

}

A. 1000
B. 11
C. 1010
D. 1001

Show Answer Answer:-C. 1010
Explanation 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. Output: $ g++ op2.cpp $ a.out 1010

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

#include <iostream>

using namespace std;

int main ()

{

int x, y;

x = 5;

y = ++x * ++x;

cout << x << y;

x = 5;

y = x++ * ++x;

cout << x << y;

return 0;

}

A. 749735
B. 736749
C. 367497
D. 367597

Show Answer Answer:-A. 749735
Explanation Because of the precedence the pre-increment and post increment operator, we got the output as 749736. Output: $ g++ op.cpp $ a.out 749735

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

#include <iostream>

using namespace std;

int main()

{

int a = 5, b = 6, c;

c = (a > b) ? a : b;

cout << c;

return 0;

}

A. 4
B. 5
C. 6
D. 7

Show Answer Answer:-C. 6
Explanation Here the condition is false on conditional operator, so the b value is assigned to c. Output: $ g++ op1.cpp $ a.out 6

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

#include <iostream>

using namespace std;

main()

{

double a = 21.09399;

float b = 10.20;

int c ,d;

c = (int) a;

d = (int) b;

cout << c <<‘ ‘<< d;

return 0;

}

A. 20 10
B. 40 21
C. 30 20
D. 21 10

Show Answer Answer:-D. 21 10
Explanation In this program, we are casting the operator to integer, So it is printing as 21 and 10. Output: $ g++ op5.cpp $ a.out 21 10

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page