title: Why does cudaMalloc() use pointer to pointer?
body: <p>For example, <code>cudaMalloc((void**)&amp;device_array, num_bytes);</code></p>
  
  <p>This question has been <a href="https://stackoverflow.com/questions/7989039/use-of-cudamalloc-why-the-double-pointer">asked</a> before, and the reply was "because <code>cudaMalloc</code> returns an error code", but I don't get it - what has a double pointer got to do with returning an error code? Why can't a simple pointer do the job?</p>
  
  <p>If I write</p>
  
  <pre><code>cudaError_t catch_status;
  catch_status = cudaMalloc((void**)&amp;device_array, num_bytes);
  </code></pre>
  
  <p>the error code will be put in <code>catch_status</code>, and returning a simple pointer to the allocated GPU memory should suffice, shouldn't it?</p>