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;
}
1234
4321
12344321
12341234
43211234
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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?

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:

Your comments will be displayed after verification.