0Pricing
C Academy · Lesson

Using qsort

The standard library sort.

The Standard Library Sort

C's standard library provides qsort in <stdlib.h>. It sorts any array given a comparison function, so you rarely need to write your own sort.

The qsort Signature

The prototype is:

  • base pointer to the first element
  • nmemb number of elements
  • size bytes per element
  • compar a comparison function pointer

void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));

All lessons in this course

  1. Bubble and Insertion Sort
  2. Quicksort
  3. Mergesort
  4. Using qsort
← Back to C Academy