Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    class Example
    {
    public:
    int m, n;
    Example() {};
    Example(int, int);
    Example operator + (Example);
    };
    Example::Example (int p, int q)
    {
    m = p;
    n = q;
    }
    Example Example::operator+ (Example parameter)
    {
    Example container;
    container.m = m + parameter.m;
    container.n = n + parameter.n;
    return (container);
    }
    int main ()
    {
    Example p (3,4);
    Example q (6,5);
    Example R;
    R = p + q;
    cout << R.m << "," << R.n;
    return 0;
    }
    1. 9,9
    2. 3,4
    3. 6,5
    4. Compilation Error
    5. None of these
Correct Option: A

In this program, we are adding the first number of p with first number of q by using operator function and also we are adding second number by this method also.



Your comments will be displayed only after manual approval.