This might be a very trivial question but why am I still able to access the values from the array(which was dynamically allocated) even after using the delete
keyword.
#include <iostream>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
int *arr = new int[10];
for(int i=0;i<10;i++){
arr[i] = i+1;
}
for(int i=0;i<10;i++)
{
cout << arr[i] << " ";
}
cout << endl;
delete[] arr;
for(int i=0;i<10;i++){
cout << arr[i] << " ";
}
return 0;
}
What i know is that using the delete
keyword frees the memory which was allocated.
I am pretty new to C++. Any help would be appreciated.