Skip to content
main-logo
  • +91 637-050-2482
  • santuitreturns@gmail.com
Menu
Menu
  • Home
  • Income Tax
    • Income From Salary
    • Profit or gain from Business/Profession.
    • Capital Gain
    • Income From Other Sources
    • 80C to 80U
    • TDS & TCS
    • ITR FORMS
  • International Taxation
    • Transfer Pricing
    • Non-Resident Taxation
    • Foreign Tax Credit (FTC)
    • Model Tax Convention
    • Base Erosion and Profit Shifting (BEPS)
  • GST
  • Accounting
  • MCQs
    • NEET
    • NEET QUIZ TEST
    • NEET PG MCQ’s
    • NEET PG QUIZ TEST
    • Civil Engineering
    • Mechanical Engineering MCQs
    • CHSL EXAM
      • Logical Reasoning
  • Others
    • Job Tips
  • CA Courses
    • CA Inter/IPCC

10+ TOP C++ MCQs on Operator Overloading – 2

Posted on September 23, 2023

1. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class A
{
	static int a;
    public:
	void show()
        {
		a++;
		cout<<"a: "<

A. Error as a private member a is referenced outside the class
B. Segmentation fault
C. No output
D. Program compiles successfully but gives run-time error

View Answer

Answer: C

Explanation: 

 As every static member must be initialized and we have initialized variable ‘a’ so no run time error. Also as variable ‘a’ is a static member and is referenced using the class for initialization therefore no compiler error.

2. What happens when objects s1 and s2 are added?
string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);

A. Error because s1+s2 will result into string and no string has substr() function
B. Segmentation fault as two string cannot be added in C++
C. The statements runs perfectly
D. Run-time error

View Answer

Answer: A

Explanation:

 string is class in C++, therefore when we do (s1+s2) a temporary object is created which stores the result of s1+s2 and then that object calls the function substr() and as that is an object of string class hence substr is a callable function for that temporary string object.

3. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class A
{
	static int a;
    public:
	A()
        {
		cout<<"Object of A is created\n";
	}
	void show()
        {
		a++;
		cout<<"a: "<

A. Runs perfectly
B. Run-time Error
C. Segmentation fault
D. Compile-time Error

View Answer

Answer: D

Explanation:

 As the programmer has not defined what action should be taken when two objects of class A are added, so the program doesn’t know and gives compile time error.

4. What is operator overloading in C++?

A. Overriding the operator meaning by the user defined meaning for user defined data type
B. Redefining the way operator works for user defined types
C. Ability to provide the operators with some special meaning for user defined data type
D. All of the mentioned

View Answer

Answer: D

Explanation:

 Operator overloading helps programmer to give his/her own meaning to an operator for user defined data types(eg, classes).

5. What is the syntax of overloading operator + for class A?

A. A operator+(argument_list){}
B. A operator[+](argument_list){}
C. int +(argument_list){}
D. int [+](argument_list){}

View Answer

Answer: A

Explanation:

The general syntax for operator overloading is:
return_type operator_keywordOperator(argument_list){}
eg.
A opeartor+(argument_list){}

6. How many approaches are used for operator overloading?

A. 1
B. 2
C. 3
D. 4

View Answer

Answer: C

Explanation:

 There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.

7. Which of the following operator cannot be overloaded?

A. +
B. ?:
C. –
D. %

View Answer

Answer: B

Explanation:

 ?:, :: and . cannot be overloaded +, -, % can be overloaded.

8. Which of the following operator can be overloaded?

A. ?:
B. ::
C. .
D. ==

View Answer

Answer: D

Explanation:

 ?:, :: and . cannot be overloaded whereas == can be overloaded.

9. Which of the following operator cannot be used to overload when that function is declared as friend function?

A. -=
B. ||
C. ==
D. []

View Answer

Answer: D

Explanation:

 When an operator overlaoded function is declared as friend function then [] cannot be overloaded.

10. Which of the following operator can be used to overload when that function is declared as friend function?

A. []
B. ()
C. ->
D. |=

View Answer

Answer: D

Explanation:

When an operator overlaoded function is declared as friend function then [], () and -> cannot be overloaded.

11. In case of non-static member functions how many maximum object arguments a unary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0

View Answer

Answer: D

Explanation:

 In the case of non-static member functions unary operator overloaded function should not take any object argument.

12. In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0

View Answer

Answer: A

Explanation:

 In the case of non-static member functions binary operator overloaded function should take maximum one object argument only.

13. In the case of friend operator overloaded functions how many maximum object arguments a unary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0

View Answer

Answer: A

Explanation:

 In the case of friend operator overloaded functions unary operator overloaded function should take maximum one object argument only.

14. In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0

View Answer

Answer: B

Explanation:

 In the case of friend operator overloaded functions binary operator overloaded function should take maximum two object argument.

15. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class A
{
	static int a;
 
   public:
	void show()
        {
		a++;
		cout<<"a: "<

A. Run-time Error
B. Runs perfectly
C. Segmentation fault
D. Compile-time error

View Answer

Answer: D

Explanation:

 .(dot) operator cannot be overloaded therefore the program gives error.

    You May Also Like...

  • 10+ TOP C++ MCQs on OOPs Concept – 3
  • 10+ TOP C++ MCQs on OOPs Concept – 4
  • 10+ TOP MCQs on C++ vs C
  • 10+ TOP C++ MCQs on Floating Point Types
  • 10+ TOP C++ MCQs on Sizes
  • 10+ TOP C++ MCQs on Void
  • 10+ TOP C++ MCQs on References – 2
  • 10+ TOP C++ MCQs on References – 3

Leave a Reply Cancel reply

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

Quick Links

  • Home
  • About Us
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Contact Us

Categories

  • Income Tax
  • International Taxation
  • GST
  • MCQs
  • Others
  • CA Courses

Latest Posts

  • Five changes in ITR forms of FY 2024-25 (AY 2025-26)
  • Form 10-IEA: Option to Choose Old Tax Regime
  • What is Section 54EC of the Income Tax Act?
  • What is Section 54F of the Income Tax Act?
©2025 Online Solves. All rights Reserved | Developed by AlgoPage IT Solutions Pvt. Ltd.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT