My Report

C++ Operator Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of the following operator can be overloaded?

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

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

4. Which of the following operator cannot be overloaded?

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

#include <iostream>
#include <string>
using namespace std;
class A
{
	static int a;
	
   public:
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
	void operator.()
        {
		cout<<"Objects are added\n";
	}
};

class B
{
     public:
};

int main(int argc, char const *argv[])
{
	A a1, a2;
	return 0;
}

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

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

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

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

10. What is operator overloading in C++?

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

#include <iostream>
#include <string>
using namespace std;
class A
{
	static int a;
    public:
	A()
        {
		cout<<"Object of A is created\n";
	}
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
};

class B
{
    public:
};

int main(int argc, char const *argv[])
{
	A a1, a2;
	A a3 = a1 + a2;
	return 0;
}

12. What happens when objects s1 and s2 are added?

string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);

13. How many approaches are used for operator overloading?

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

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

#include <iostream>
#include <string>
using namespace std;
class A
{
	static int a;
    public:
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
};

int A::a = 5;

int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.