title: Allocate space for struct pointer in subfunction
body: <p>How can I allocate memory for a struct pointer and assign value to it's member in a subfunction?</p>
  
  <p>The following code will compile but not execute:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct _struct {char *str;};
  void allocate_and_initialize(struct _struct *s)
  {
      s = calloc(sizeof(struct _struct), 1);
      s-&gt;str = calloc(sizeof(char), 12);
      strcpy(s-&gt;str, "hello world");
  }
  int main(void)
  {
      struct _struct *s;
      allocate_and_initialize(s);
      printf("%s\n", s-&gt;str);
  
      return 0;
  }
  </code></pre>