C++ Programming Questions and Answers – Operators

This section on 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, walkin 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 detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ language interview questions on “Operators” along with answers, explanations and/or solutions:

1. Which operator is having right to left associativity in the following?
a) Array subscripting
b) Function call
c) Addition and subtraction
d) Type cast
View Answer


2. Which operator is having the highest precedence?
a) postfix
b) unary
c) shift
d) equality
View Answer

Explanation:The operator which is having highest precedence is postfix and lowest is equality.

3. What is this operator called ?: ?
a) conditional
b) relational
c) casting operator
d) none of the mentioned
View Answer

Explanation:In this operator, if the condition is true means, it will return the first operator, otherwise second operator.

4. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a;
  6.         a = 5 + 3 * 5;
  7.         cout << a;
  8.         return 0;
  9.     }

a) 35
b) 20
c) 25
d) 30
View Answer

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

5. What is the use of dynamic_cast operator?
a) it converts virtual base class to derived class
b) it converts virtual base object to derived objeccts
c) it will convert the operator based on precedence
d) None of the mentioned
View Answer

Explanation: Because the dynamic_cast operator is used to convert from base class to derived class.

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5, b = 6, c, d;
  6.         c = a, b;
  7.         d = (a, b);
  8.         cout << c << 't' << d;
  9.         return 0;
  10.     }

a) 5 6
b) 6 5
c) 6 7
d) none of the mentioned
View Answer

Explanation: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.
$ g++ op3.cpp
$ a.out
5 6

7. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i, j;
  6.         j = 10;
  7.         i = (j++, j + 100, 999 + j);
  8.         cout << i;
  9.         return 0;
  10.     }

a) 1000
b) 11
c) 1010
d) 1001
View Answer

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.
$ g++ op2.cpp
$ a.out

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int x, y;
  6.         x = 5;
  7.         y = ++x * ++x;
  8.         cout << x << y;
  9.         x = 5;
  10.         y = x++ * ++x;
  11.         cout << x << y;
  12.         return 0;
  13.     }

a) 749736
b) 736749
c) 367497
d) none of the mentioned
View Answer

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

9. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5, b = 6, c;
  6.         c = (a > b) ? a : b;
  7.         cout << c;
  8.         return 0;
  9.     }

a) 6
b) 5
c) 4
d) 7
View Answer

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

10. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     main()
  4.     {
  5.         double a = 21.09399;
  6.         float b = 10.20;
  7.         int c ,d;
  8.         c = (int) a;
  9.         d = (int) b;
  10.         cout << c <<'t'<< d;
  11.         return 0;
  12.     }

a) 20 10
b) 10 21
c) 21 10
d) none of the mentioned
View Answer

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

Sanfoundry Global Education & Learning Series – C++ Programming Language.

Here’s the list of Best Reference Books in C++ Programming Language.

To practice all features of C++ programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C++.

Subscribe Newsletter & Posts

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.

Practice Interview Questions & Answers, Quizzes, Objective, Multiple Choice Aptitude Tests for Freshers and Experienced People in these topics - Learn C, C++, Java and C# Programming with coding example on Simple problems as well as tough Algorithms and Data-structures along with runtime output: - C Programs, Data-Structures and Algorithms, C++ Algorithms, Java Algorithms, C# Programs, Android Programs in Java

C Tutorials and Linux Commands Tutorial - C Tutorials, Linux Commands

Career Mentoring with our Founder / CTO - Read More

1000 C++ MCQs | Quiz

Character Types
Integer Types
Floating Point Types
Pointers into Arrays
Pointer to Void
Comments and Indentation
Function Declarations
Argument Passing
Value Return
Overloaded Function Names
Default Arguments
Unspecified Number of Arguments
Pointer to Function
Modularization and Interfaces
Header Files Usage
User Defined Types
Operator Functions
Complex Number Type
Conversion Operators
Large Objects
Essential Operators
Function Call
Increment and Decrement
String Class
Derived Classes
Abstract Classes
Design of Class Hierarchies
Class Hierarchies & Abstract Classes
Simple String Template
Function Templates
Template Arguments for Policy Usage
Derivation and Templates
Error Handling
Grouping of Exceptions
Catching Exceptions
Resource Management
Exceptions That Are Not Errors
Exception Specifications
Uncaught Exceptions
Exceptions and Efficiency
Error Handling Alternatives
Standard Exceptions
Class Hierarchies Introduction
Multiple Inheritance
Access Control
Run Time Type Information
Pointers to Members
Free Store
Standard Library Design
Container Design
Sequence Adapters
Associative Containers
Almost Containers
Defining a New Container
Standard Library Algorithms
Sequences and Containers
Function Objects
Nonmodifying Sequence Algorithms
Modifying Sequence Algorithms
Stored Sequences
Min and Max
C Style Algorithms
Iterators and Sequences
Checked Iterators
String Characters
Basic String
C Standard Library
Output Stream
Input Stream
File Streams and String Streams
C Input Output
Numeric Limits
Standard Mathematical Functions
Vector Arithmetic
Generalized Numeric Algorithms
Random Numbers
Follow Manish & Sanfoundry