title: How to sort an array by passing to a function as pointer using c?
body: <p>Consider an array, which is passed to the function <code>swap()</code>, as illustrated in the following quote. I want to implemented a variant of this <code>swap()</code> function in order to sort my array.</p>
  
  <blockquote>
    <p>These inefficiencies can be removed by an implementation as suggested bu the array concept of the C programming language. The idea is to access array elements through pointers. Another idea is to store addresses that are used multiple times.</p>
  
  <pre><code>void swap(int *p, int *q) {
      int t, ai, aj;
      ai &lt;- *p; aj &lt;- *q;
      if (ai &gt; aj) {
          t &lt;- aj;
          *q &lt;- ai;
          *p &lt;- t;
      }
  }
  </code></pre>
    
    <p>Looking more closely at this new code reveals that the temporary variable <code>t</code> can be eliminated as well.</p>
  </blockquote>
  
  <p>I have done it in the following way, but fail to sort the array. Can you check for the error why it does not sort the array?</p>
  
  <pre><code>void swap(int array1[], int array2[])
  {
      int temp, ai, aj;
      ai = *array1;
      aj = *array2;
      if (ai &gt; aj) /* For decreasing order use &lt; */
      {
          temp = aj;
          aj = ai;
          ai = temp;
      }
  }
  
  int main()
  {
      int array[100], n, c, d, swap;
  
      printf("Enter number of elements\n");
      scanf("%d", &amp;n);
  
      printf("Enter %d integers\n", n);
  
      for (c = 0; c &lt; n; c++)
          scanf("%d", &amp;array[c]);
  
      for (c = 0; c &lt; (n - 1); c++)
      {
          for (d = 0; d &lt; n - c - 1; d++)
          {
              swap(array[c], array[d]);
          }
      }
  
      printf("Sorted list in ascending order:\n");
  
      for (c = 0; c &lt; n; c++)
          printf("%d\n", array[c]);
  
      return 0;
  }
  </code></pre>