title: Arrays of pointer dereferencing
body: <p>I want to  a function named sortPointers() that sets an array of integer pointers to point to the elements of another array in ascending order.</p>
  
  <p><a href="https://i.stack.imgur.com/nogWr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nogWr.png" alt="enter image description here"></a></p>
  
  <p>What I have done so far is </p>
  
  <pre><code>      void sortP(int src[], int *ptrs[], int n)
   {
       int temp;
      for(int i = 0; i&lt; n ; i++)
      {
          ptrs[i] = &amp; src[i]; // assign the address of each number in the src[] to the array of pointers
      }
  
      while (1)
      {
          int flag = 0;
          for(int i = 0; i&lt; n;i++)
              {
                      if ( *(ptrs[i]) &gt; *(ptrs[i+1])) //bubble sort
                  {
                       temp = *(ptrs[i]);
                       *(ptrs[i]) = *(ptrs[i+1]);
                       *(ptrs[i+1]) = temp;
                       flag = 1;
                  }
              }
              if(flag == 0);
              break;
        }
  
        for(int i = 0; i&lt; n;i++)
        {
            printf("%i\n",ptrs[i]);
        }
   }
  </code></pre>
  
  <p>In main function , I call this function</p>
  
  <pre><code>main()
  {
      int a[5] = {5,4,3,2,1};
      int *ptrs[5]= {&amp;a[0],&amp;a[1],&amp;a[2],&amp;a[3],&amp;a[4]};
   sortP(a, *ptrs, 5);
  
  }
  </code></pre>
  
  <p>My result are addresses, If I want to  print out the actual value that the pointers point to (1,2,3,4,5) ,what should I change in the printf()?</p>
  
  <p>THanks</p>
  
  <p>P.S.  I try *ptrs[i] before , but I got strange number though , not the ones in src[]..</p>