title: What is the difference between double pointers and single pointer in C functions
body: <p>I'm new to the C programming language and beginning to mess around with pointers and allocating memory to objects. I wanted to make a simple program that would read in (x) elements from the user and simply print them out using functions.</p>
  <p>This was my inital code at the beginning. The code was reading in the user input properly but it gave the wrong output and crashed when displaying elements within the main function.</p>
  <pre><code>int main() {
      int *myArr;
      int myArrSize;
      getInputArr(&amp;myArrSize, &amp;myArr);
  
      for (int i = 0; i &lt; myArrSize; i++) {
          printf(&quot;Element No.%i: %i\n&quot;, i, myArr[i]);
      }
  
      free(myArr);
      return 0;
  }
  
  void getInputArr(int *arrSize, int *arr) {
      printf(&quot;Please Enter Length of Array: \n&quot;);
      scanf(&quot;%i&quot;, arrSize);
  
      arr = (int *) malloc(*arrSize * sizeof(int));
  
      printf(&quot;Enter %i Numbers!\n&quot;, *arrSize);
      for (int i = 0; i &lt; *arrSize; i++) {
          scanf(&quot;%i&quot;, &amp;arr[i]);
      }
  }
  </code></pre>
  <p>After messing around, I finally got it to work using double pointers but I am unsure how it completely works, could someone explain why the code below behaves as expected?</p>
  <pre><code>int main() {
      int *myArr;
      int myArrSize;
      getInputArr(&amp;myArrSize, &amp;myArr);
  
      for (int i = 0; i &lt; myArrSize; i++) {
          printf(&quot;Element No.%i: %i\n&quot;, i, myArr[i]);
      }
  
      free(myArr);
      return 0;
  }
  
  void getInputArr(int *arrSize, int **myArr) {
      printf(&quot;Please Enter Length of Array: \n&quot;);
      scanf(&quot;%i&quot;, arrSize);
  
      *myArr = (int *) malloc(*arrSize * sizeof(int));
  
      printf(&quot;Enter %i Numbers!\n&quot;, *arrSize);
      for (int i = 0; i &lt; *arrSize; i++) {
          scanf(&quot;%i&quot;, &amp;((*myArr)[i]));
      }
  }
  </code></pre>