title: Initialize array in function
body: <p>When I want to initialize a pointer to an array through the function, I am doing the following:</p>
  
  <p>Initialize and destroy array through functions:
  </p>
  
  <pre><code>int initArr(int **b)
  {
      int *arr = (int *) malloc(sizeof(int)*2);
  
      if(arr == NULL)
          return 0;
  
      *b = arr;
      arr = NULL;
      return 1;
  }
  
  void destroyArr(int *b)
  {
      free(b); 
      b = NULL;
  }
  </code></pre>
  
  <p>Initialize pointer to array: 
  </p>
  
  <pre><code>int *pArr;
  int initStatus = initArr(&amp;pArr);
  
  if(initStatus == 0)
  {
      printf("%s", "error");
      return 0;
  }
  </code></pre>
  
  <p>Working with pointer to array:
  </p>
  
  <pre><code>*pArr = 1;
  *(pArr + 1) = 2;
  
  printf("0 = %i\n", *pArr);
  printf("1 = %i\n", *(pArr + 1));
  </code></pre>
  
  <p>Destroy pointer to array:
  </p>
  
  <pre><code>destroyArr(pArr);
  pArr = NULL;
  </code></pre>
  
  <p>Is this correct and safe?</p>