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;
}
Discussion:
2 comments Page 1 of 1.
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.
Then, objB(objA) and objC = objA calls the Copy constructor.
Divya Nesana said:
6 years ago
Structure of copy constructor is wrong! It should be "IndiaBix(const IndiaBix &objB)".
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers