class practice
{
public:
practice (){};
practice (int a)
{variable1++;
variable2=a;}
~practice () {variable1--;}
int getvar(){return variable2;}
staticint variable1;
private:
int variable2;
};
int practice::variable1=0;
int main()
{
constint max=3;
practice *PPointer[max];
for (int i=1;i<=max;i++)
{PPointer[i]=new practice(i);
cout<<practice::variable1<<endl<<PPointer[i]->getvar()<<endl;}
for (int j=1; j<=max;j++)
{delete PPointer[j];
PPointer[j]=0;
cout<<practice::variable1<<endl;}
return 0;
}
When you allocated your pointers at line 23, they were allocated from [0] to [2].
In both of your for loops, you indexing from [1] to [3].
[3] is out of range.