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 castExplanation
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. postfixExplanation
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. conditionalExplanation
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. 20Explanation
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 20Q 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 classExplanation
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 6Explanation
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 6Q 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. 1010Explanation
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 1010Q 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. 749735Explanation
Because of the precedence the pre-increment and post increment operator, we got the output as 749736. Output: $ g++ op.cpp $ a.out 749735Q 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. 6Explanation
Here the condition is false on conditional operator, so the b value is assigned to c. Output: $ g++ op1.cpp $ a.out 6Q 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
Leave a Reply