MCQs
In this program, there will arise an ambiguous overload for 5.
Operator overloading is the way adding operation to the existing operators.
In this program, -> operator is used to describe the member of the class and so we are getting this output.
Output:
$ g++ char4.cpp
$ a.out
10 10
None.
Answer: (a)
Explanation:We are using two operator functions and executing them and result is printed according to the order.
Output:
$ g++ oper2.cpp
$ a.out
operator+
operator+=
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
public:
6.
int x, y;
7.
sample() {};
8.
sample(int, int);
9.
sample operator + (sample);
10.
};
11.
sample::sample (int a, int b)
12.
{
13.
x = a;
14.
y = b;
15.
}
16.
sample sample::operator+ (sample param)
17.
{
18.
sample temp;
19.
temp.x = x + param.x;
20.
temp.y = y + param.y;
21.
return (temp);
22.
}
23.
int main ()
24.
{
25.
sample a (4,1);
26.
sample b (3,2);
27.
sample c;
28.
c = a + b;
29.
cout
In this program, we are adding the first number of a with first number
of b by using opertor
function and also we are adding second number by
this method also.
Output:
$ g++ oper.cpp
$ a.out
7, 3
We have to declare the operator function by using operator, operator
sign. Example "operator +"
where operator is a keyword and + is the
symbol need to be overloaded.
None.
None.