C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 40)
40.
What is correct about the following program?
#include<iostream.h> 
class Base
{
    int x, y, z; 
    public: 
    Base()
    {
        x = y = z = 0;
    }
    Base(int xx, int yy = 'A', int zz = 'B')
    {
        x = xx;
        y = x + yy;
        z = x + y;
    }
    void Display(void)
    {
        cout<< x << " " << y << " " << z << endl;
    }
};
class Derived : public Base
{
    int x, y; 
    public:
    Derived(int xx = 65, int yy = 66) : Base(xx, yy)
    {
        y = xx; 
        x = yy;
    }
    void Display(void)
    {
        cout<< x << " " << y << " ";
        Display(); 
    }
};
int main()
{
    Derived objD;
    objD.Display();
    return 0; 
}
The program will report compilation error.
The program will run successfully giving the output 66 65.
The program will run successfully giving the output 65 66.
The program will run successfully giving the output 66 65 65 131 196.
The program will produce the output 66 65 infinite number of times (or till stack memory overflow).
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
21 comments Page 2 of 3.

Nissy said:   4 years ago
Can anyone explain why it is a recursive function?

Nishant said:   2 years ago
I think the correct answer is option E.

Dharamsingh Rajput said:   7 years ago
E is the right option according to me.

ARNAB said:   1 decade ago
DevCpp confirms the answer to be E.

R Y said:   3 years ago
The Correct answer will be E.
(1)

Naina said:   9 years ago
Can anyone explain properly.

Pooja said:   8 years ago
The correct answer is E.

Jitendra said:   8 years ago
The correct answer is E.

Akshay said:   7 years ago
E is the right option.

Zufex said:   7 years ago
E is the right option.


Post your comments here:

Your comments will be displayed after verification.