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.
SOWJANYA said:
1 decade ago
Can anyone please clear my doubt?
In program we passed the value 4 how can it prints 1 first? Why it prints the value 1 first? Can anyone explain the procedure how it will?
In program we passed the value 4 how can it prints 1 first? Why it prints the value 1 first? Can anyone explain the procedure how it will?
Jyoti said:
1 decade ago
When objects are created constructor is called again and again but destructor destroys the object in reverse order.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers