C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 18)
18.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
        IndiaBix()
        {
            x = 0;
            y = 0; 
        }
        IndiaBix(int xx, int yy)
        {
            x = xx;
            y = yy; 
        }
        IndiaBix(IndiaBix *objB)
        {
            x = objB->x;
            y = objB->y; 
        }
        void Display()
        {
            cout<< x << " " << y;
        }
};
int main()
{
    IndiaBix objBix( new IndiaBix(20, 40) );
    objBix.Display();
    return 0; 
}
The program will print the output 0 0 .
The program will print the output 20 40 .
The program will print the output Garbage Garbage .
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Shruti said:   1 decade ago
Answer is 20 40. New IndiaBix is passed as an object, consider it as a copy constructor argument.

Shrey said:   1 decade ago
@ Shruti ..You are right!! answer is 20 40

Post your comments here:

Your comments will be displayed after verification.