title: Creating a function to check if malloc succeeded
body: <p>So I am doing a small project which involves using the <code>malloc</code>, <code>realloc</code> and <code>calloc</code> functions from time to time. I understood that after every allocation I should be checking if it failed and it points to null like so:</p>
  
  <pre><code>int* arr = malloc(size*sizeof(int));
  
  if (!arr)
  {
        printf("ERROR! Not enough memory!\n");
        exit(1); // to exit the program immedietly.
  }
  </code></pre>
  
  <p>and I was wondering if it is okay to create a method that will do just that for every kind of pointer like so:</p>
  
  <pre><code>void checkOutOfMemory(const void* p) //gets a pointer and exit program if points to null.
  {
      if (!p)
      {
          printf("ERROR! Out of memory!\n");
          exit(1);
      }
  }
  </code></pre>
  
  <p>I mean, it works so far, but I started wondering if there are any special cases I didn't know about.</p>