title: How to return dynamic array from void function in c?
body: <p>I want to return a dynamic array by reference from a void function.
  I already searching 3 hours for the answer, couldn't find anything helpfull.
  Here is my simplified code :</p>
  
  <pre><code>main()
  {
      int **a;
  
      xxx(&amp;a);
  
      printf("%d\n\n", a[1]);
  
  }
  
  void xxx(int **a)
  {
      int i;
  
      *a = (int*)malloc(5 * 4);
  
      for (i = 0; i &lt; 5; i++)
          a[i] = i;
      printf("%d\n\n", a[1]);
  }
  </code></pre>
  
  <p>I just want to allocate dynamic array in the "xxx" Function and return it by reference to main, than I want to print it or use it for something else. Thanks in advance :)</p>
  
  <p>edit </p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
   #define MACROs
   #define _CRT_SECURE_NO_WARNINGS
  
   void xxx(int **a);
  
  
   int main(void)
   {
     int *a;
  
     xxx(&amp;a);
  
     printf("%d\n\n", a[1]);
   }
  
  
   void xxx(int **a)
   {
     int i;
  
     *a = malloc(5 * sizeof(**a));
  
     for (i = 0; i &lt; 5; i++)
          a[i] = i;
     printf("%d\n\n", a[1]);
   }
  </code></pre>