title: Passing pointer by reference in C
body: <p>Fairly new to c coding with background from c++. I have a simple program to sort an array using a function. I need to pass the int pointer by reference to the sort() function so that the compiler won't create a copy and after function call the array will be sorted. If I don't pass the reference, then after function ends the array will remain unsorted.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void sort(int* &amp; arr, int s, int e)
  {
    int temp = 0, i, j;
    for (i=0;i&lt;e;i++)
    {
      for (j=i+1;j&lt;e;j++)
      {
          if (*arr[i]&gt;*arr[j])
          {
              temp = *arr[i];
              *arr[i] = *arr[j];
              *arr[j] = temp;
          }
      }
    } 
  }
  
  int main()
  {   
      int* arr = malloc(sizeof(int)*10);
      int i;
  
       for (i=0;i&lt;10;i++)
           arr[i] = i+1;
       printf("Array before sorting:\n");
       for (i=0;i&lt;10;i++)
           printf("%d  ", arr[i]);
       printf("\n");
  
       sort(arr, 0, 10);
       printf("Array after sorting:\n");
       for (i=0;i&lt;10;i++)
           printf("%d  ", arr[i]);
       printf("\n");
  
       return 0;
  }
  </code></pre>
  
  <p>I have also come to know that c doesn't allow pass by reference in a function, so how can I solve this issue?</p>