C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 17)
17.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
        IndiaBix()
        {
           x = 0;
        }
        IndiaBix(int xx)
        {
            x = xx; 
        }
        IndiaBix(IndiaBix &objB)
        {
            x = objB.x; 
        }
        void Display()
        {
            cout<< x << " ";
        }
};
int main()
{
    IndiaBix objA(25);
    IndiaBix objB(objA);
    IndiaBix objC = objA;
    objA.Display();
    objB.Display();
    objC.Display();
    return 0; 
}
The program will print the output 25 25 25 .
The program will print the output 25 Garbage 25 .
The program will print the output Garbage 25 25 .
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.

Divya Nesana said:   6 years ago
Structure of copy constructor is wrong! It should be "IndiaBix(const IndiaBix &objB)".

Ayush said:   1 decade ago
First, xx=25 and 25 will be assigned to x.

Then, objB(objA) and objC = objA calls the Copy constructor.

Post your comments here:

Your comments will be displayed after verification.