title: C Assign Pointer to NULL
body: <p>I am misunderstanding something basic about pointers in C, this should be simple but search brings up nothing. I do not understand the behaviour of the following code;</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  void my_function(char *);
  
  int main(int argc, char *argv[]) {
      char *ptr;
      ptr = malloc(10);
  
      if(ptr != NULL) printf("FIRST TEST: ptr is not null\n");
      else printf("FIRST TEST: ptr is null\n");
  
      my_function(ptr);
  
      if(ptr != NULL) printf("SECOND TEST: ptr is not null\n");
      else printf("SECOND TEST: ptr is null\n");
  }
  
  void my_function(char *a) {
      a = NULL;
  }
  </code></pre>
  
  <p>Which outputs;</p>
  
  <pre><code>FIRST TEST: ptr is not null
  SECOND TEST: ptr is not null
  </code></pre>
  
  <p>Why does the second test still see the pointer as not NULL? I am trying to use a NULL pointer assignment as a sort of 'return flag' to indicate a certain failure of the function. But upon testing the pointer afterwards, it does not seem to be NULL.</p>