Site icon T4Tutorials.com

Operator overloading Solved MCQ’s (OOP)

Operator overloading Solved MCQ’s (OOP)

Let us see the important Operator overloading Solved MCQ’s. Operator overloading is a very important topic of object-oriented programming (OOP).

1. we can define a binary operator as :
A. The operator that performs its action on two operand
B. The operator that performs its action on three operand
C. The operator that performs its action on any number of operands
D. The operator that performs its action on a single operand

Answer - Click Here:
A

2. ______ is not an operator overloaded by the C++ language.
A. <<.
B. +.
C. pow
D. >>.

Answer - Click Here:
C

3. correct example of a binary operator is _______.
A. —
B. +
C. ++
D. Dereferencing operator(*)

Answer - Click Here:
B

4. true about streams is ______.
a. a sequence of bytes
b. an ordered sequence
c. bytes can go through the stream simultaneously
d. Bytes will go out at last that enters first into the stream
A. A only
B. A and B
C. C only
D. A and D

Answer - Click Here:
B

5. ____ is a correct example of a unary operator.
A. /
B. —
C. &
D. ==

Answer - Click Here:
B

6. when we use an operator on user-defined class objects, operator overloading:
A. always be used must
B. never be used must
C. with three exceptions must never be used
D. with three exceptions must always be used

Answer - Click Here:
D

7. Ternary operator is shown as _____.
A. ===
B. &&
C. ?:
D. |||

Answer - Click Here:
C

8. Overloading the addition (+) operator is correct function name OF :
A. operator(+).
B. operator_+.
C. operator+.
D. operator:+.

Answer - Click Here:
A

9. Choose the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class complex
{
int i;
int j;
public:
complex(int a, int b)
{
i = a;
j = b;
}
complex operator+(complex c)
{
complex temp;
temp.i = this->i + c.i;
temp.j = this->j + c.j;
return temp;
}
void show(){
cout<<"Please note it that Complex Number is: "<<i<<" + i"<<j<<endl;
}
};
int main(int argc, char const *argv[])
{
complex c1(1,2);
complex c2(3,4);
complex c3 = c1 + c2;
c3.show();
return 0;
}

A. Error
B. 4 + i6
C. Segmentation fault
D. 2 + i2

Answer - Click Here:
A

10. ________ operators cannot be overloaded?
A. The [ ] operator.
B. The -> operator.
C. The . operator.
D. The & operator

Answer - Click Here:
C

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

#include <iostream>
#include <string>
using namespace std;
class com
{
int i;
int j;
public:
complex(){}
com(int a, int b)
{
i = a;
j = b;
}
com operator+(complex c)
{
comPlex temp;
temp.i = this->i + c.i;
temp.j = this->j + c.j;
return temp;
}
void show(){
cout<<"Please note it that Complex Number is: "<<i<<" + i"<<j<<endl;
}
};
int main(int argc, char const *argv[])
{
com c1(1,2);
com c2(3,4);
com c3 = c1 + c2;
c3.show();
return 0;
}

A. Segmentation fault
B. Complex Number: 4 + i6(ANS)
C. Complex Number: 2 + i2
D. Error

Answer - Click Here:
B

12. Choose the correct statement which is false baout the operator.
A. Overloading cannot change how an operator works on built-in types.
B. New operators can never be created.
C. The precedence of an operator cannot be changed by overloading.
D. operators can change the number of arguments Certain overloaded they take.(ANS)

Answer - Click Here:
D

13. The output of the following C++ code will be _____.

#include <iostream>
#include <string>
using namespace std;
class compl
{
int i;
int j;
public:
compl(){}
compl(int a, int b)
{
i = a;
j = b;
}
compl operator+(compl c)
{
compl temp;
temp.i = this->i + c.i;
temp.j = this->j + c.j;
return temp;
}
void operator+(compl c)
{
compl temp;
temp.i = this->i + c.i;
temp.j = this->j + c.j;
temp.show_poss();
}
void show(){
cout<<"Complex Number: "<<i<<" + i"<<j<<endl;
}
void show_poss(){
cout<<"The result after addition will be looks like: "<<i<<" + i"<<j<<endl;
}
};
int main(int argc, char const *argv[])
{
compl c1(1,2);
compl c2(3,4);
c1 + c2;
return 0;
}

A. Error
B. Segmentation fault
C. Complex Number: 4 + i6
D. Complex Number: 2 + i2

Answer - Click Here:
A

14. To implicitly overload the += operator:
A. Only the = operator needs to be overloaded.
B. Only the + operator needs to be overloaded.
C. The += operator cannot be overloaded implicitly.
D. Both the + and = operators need to be overloaded

Answer - Click Here:
C

OOP MCQs 

Programming C Plus Plus MCQs Homepage

Exit mobile version