title: How does the compare function in qsort work?
body: <p>I found this sample code online, which explains how the <code>qsort</code> function works. I could not understand what the compare function returns.</p>
  
  <pre><code>#include "stdlib.h"
  
  int values[] = { 88, 56, 100, 2, 25 };
  
  int cmpfunc (const void * a, const void * b) //what is it returning?
  {
     return ( *(int*)a - *(int*)b ); //What is a and b?
  }
  
  
  int main(int argc, _TCHAR* argv[])
  {
  
     int n;
  
     printf("Before sorting the list is: \n");
     for( n = 0 ; n &lt; 5; n++ ) {
        printf("%d ", values[n]);
     }
  
     qsort(values, 5, sizeof(int), cmpfunc);
  
     printf("\nAfter sorting the list is: \n");
     for( n = 0 ; n &lt; 5; n++ ) {
        printf("%d ", values[n]);
     }
      return 0;
  }
  </code></pre>