fork download
  1. int compare ( const void* a, const void* b )
  2. {
  3. printf("comparing %d < %d\n", *(int*)a, *(int*)b );
  4. return *(int*)a - *(int*)b;
  5. }
  6.  
  7. void test()
  8. {
  9. int a=6, b=2, c=5;
  10. void** pv = malloc (3*sizeof (void*));
  11.  
  12. if (pv)
  13. {
  14. pv[0] = &a; pv[1] = &b; pv[2] = &c;
  15. printf ("%d %d %d\n", pv[0] == &a, pv[1] == &b, pv[2] == &c );
  16. printf ( "before sorting: %d(%p) %d(%p) %d(%p)\n", *(int*)pv[0], pv[0], *(int*)pv[1], pv[1], *(int*)pv[2], pv[2] );
  17. qsort ( pv, 3, sizeof(void*), compare );
  18. printf ( "after sorting: %d(%p) %d(%p) %d(%p)\n", *(int*)pv[0], pv[0], *(int*)pv[1], pv[1], *(int*)pv[2], pv[2] );
  19. free(pv);
  20. }
  21. }
  22.  
  23. int main(void)
  24. {
  25. test();
  26. system("pause");
  27. return 0;
  28. }
Success #stdin #stdout 0.02s 5268KB
stdin
Standard input is empty
stdout
1 1 1
before sorting: 6(0xbf823304) 2(0xbf823300) 5(0xbf8232fc)
comparing -1081986304 < -1081986308
comparing -1081986300 < -1081986308
comparing -1081986300 < -1081986304
after sorting: 5(0xbf8232fc) 2(0xbf823300) 6(0xbf823304)