title: why does the output change after free(ptr) using malloc() ?? I thought the output would be NULL as I've freed the memory but it shows some numbers
body: <pre><code>#include&lt;iostream&gt;
  
  
  using namespace std;
  
  
  int main()
  {
  
  int *ptr;
  int n=5,i;
  ptr=(int*)malloc(n*sizeof(int));
  if(ptr==NULL){
      cout&lt;&lt;"Memory not allocated"&lt;&lt;endl;
      return 0;
  }
  else{
      cout&lt;&lt;"Memory allocated"&lt;&lt;endl;
       for(i=0;i&lt;n;i++){
      ptr[i]=i+1;
  
  }
  for(i=0;i&lt;n;i++){
      cout&lt;&lt;ptr[i]&lt;&lt;" ";
  
  }
  free(ptr);
  cout&lt;&lt;"\nMemory Freed\n";
  
  
   for(i=0;i&lt;n;i++){
      cout&lt;&lt;ptr[i]&lt;&lt;" ";
  
  }
  }
  
  
  return 0;
  }
  </code></pre>
  
  <p>**OUTPUT:</p>
  
  <p>Memory allocated</p>
  
  <p>1 2 3 4 5</p>
  
  <p>Memory Freed</p>
  
  <p>18682760 18677952 3 4 5**</p>
  
  <p>Why is the OUTPUT after free(ptr) is some numbers. I'm new to dynamic programming so I experimented with malloc() and calloc() when i observed this. I thought after using free(ptr) i thought the array will be NULL but it still contains some values and when i run the program again the value after free(ptr) changes. Can anyone explain ?</p>