#include #include /* for qsort */ int comp(const void *p1, const void *p2); int main() { int a[] = {1, 3, 0, 2, 5}; const size_t n = sizeof a / sizeof a[0]; const int *p; qsort(a, n, sizeof a[0], comp); /* last arg is pointer to function */ for (p = a; p < a + n; ++p) { printf("%d\n", *p); } return EXIT_SUCCESS; } int comp(const void *p1, const void *p2) /* sort in increasing numeric order */ { const int i = *(const int *)p1; /* can't dereference void * */ const int j = *(const int *)p2; if (i < j) { return -1; } if (i > j) { return 1; } return 0; }