*****Describe the output in step by step with details>>>>

#include<iostream>
using namespace std;
class A
{
    int x,y;
public:
    A(){x=10;y=10;}
    A(int a,int b){x=b;y=a;}
    ~A()
    {cout<<"X="<<x<<",";
    cout<<"Y="<<y<<endl;
    }
};
int main()
{
    cout<<"Start main\n";
    A point1(50,20);
    A point2;
    A point3(40,30);
    cout<<"End Main\n";
    return 0;
}

And your problem is? From your code, when the program ends, the destructor for class A should be called for each instance, generating something like this:

X=30,Y=40
X=10,Y=10
X=20,Y=50

Note that the output should be in reverse order of their declarations. This is what my Linux system shows from your code. This is because the destructors are called as the stack unwinds, last to first automatic variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.