logo
  • Home
  • Rank
  • Tests
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C++ Multiple Choice Questions | MCQs | Quiz

C++ Interview Questions and Answers
Practice C++ questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References
•   Pointer to Void
•   Structures
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes
•   User Defined Types
•   Objects
•   Operator Functions
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   Derived Classes
•   Abstract Classes
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Error Handling
•   Grouping of Exceptions
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Access Control
•   Run Time Type
•   Pointers to Members
•   Free Store
•   Standard Library Design
•   Container Design
•   Vector
•   Sequences
•   Sequence Adapters
•   Associative Containers
•   Almost Containers
•   Defining a New Container
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min and Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   String Characters
•   Basic String
•   C Standard Library
•   Output Stream
•   Input Stream
•   Formatting
•   File & String Streams
•   Buffering
•   Locale
•   C Input Output
•   Numeric Limits
•   Mathematical Functions
•   Vector Arithmetic
•   Numeric Algorithms
•   Random Numbers

C++ Tests

C++ Tests

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Operators

Posted on November 13, 2012 by Manish
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, 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.

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

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
View Answer

Answer: d
Explanation: There are many right to left associativity operators in C++, which means they are evaluation is done from right to left. Type Cast is one of them. Here is a link of associativity of operators: https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/cpp/cpp-built-in-operators-precedence-and-associativity.md
advertisement

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

Answer: a
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

Answer: a
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

Answer: b
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

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) none of the mentioned
View Answer

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

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 << ' ' << d;
  9.         return 0;
  10.     }

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

Answer: a
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

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

Answer: c
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

advertisement

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) 749735
b) 736749
c) 367497
d) none of the mentioned
View Answer

Answer: a
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

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

Answer: a
Explanation: Here the condition is false on conditional operator, so the b value is assigned to c.
Output:

$ g++ op1.cpp
$ a.out
6

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 <<' '<< d;
  11.         return 0;
  12.     }

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

Answer: c
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

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

C++ Practice Resources
C++ Mock Tests & Certification Test | 1000 C++ MCQs | 1000 C++ Algorithms | Best C++ Books
« Prev Page - C++ Programming Questions and Answers – Structures
» Next Page - C++ Programming Questions and Answers – Statements

« C++ Programming Questions and Answers – Structures
C++ Programming Questions and Answers – Statements »
advertisement

Deep Dive @ Sanfoundry:

  1. C# Questions and Answers
  2. C++ Questions and Answers
  3. PHP Questions and Answers
  4. Object Oriented Programming Questions and Answers
  5. C Questions and Answers
  6. C Programming Examples on Bitwise Operations
  7. R Programming Questions and Answers
  8. Programming Questions and Answers
  9. Ruby Programming Questions and Answers
  10. Python Questions and Answers
Manish Bhojasia, a technology veteran with 20+ 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:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.