C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - Programs (Q.No. 5)
5.
What will be the output of the following program?
#include<iostream.h>
int val = 0;
class IndiaBix
{
public:
IndiaBix()
{
cout<< ++val;
}
~IndiaBix()
{
cout<< val--;
}
};
int main()
{
IndiaBix objBix1, objBix2, objBix3;
{
IndiaBix objBix4;
}
return 0;
}
Discussion:
12 comments Page 2 of 2.
Roshni said:
6 years ago
Why the object objBix4 is declared within the brackets?
Swapnil Mane said:
5 years ago
First, all objects will call to constructor we get 1234.
Then all objects will call destructor we get 4321
So the answer is =12344321.
Then all objects will call destructor we get 4321
So the answer is =12344321.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers