Monday, 19 August 2013

Does assigning zero to a pointer destroy the allocated memory?

Does assigning zero to a pointer destroy the allocated memory?

My question may seem trivial for some people, but I don't understand why
this code:
double * a = new double [3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
a = 0;
for(int i=0; i<3;i++)
cout << " a[" << i << "] = " << a[i] << endl;
delete [] a ;
does not give the following result:
a[0] = 0;
a[1] = 0;
a[2] = 0;

No comments:

Post a Comment