the following is the code where I stored integers on heap and then deleted them using delete[]
int main(){
size_t n{20};
int *a =new int[n];
for (size_t i=0;i<n;i++)
{
a[i]=i;
}
delete[] a;
for (size_t k=0;k<n;k++)
{
cout<<a[k]<<" ";
}
}
The output to this shows that only the first two elements of the dynamically created array have been cleared while the rest still retain their values. Why don't all indices contain garbage value?
Output of this code: 8130008 8131488 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19