New Generic pointer that can point to any data type
1st Parameter
Pointer to the base of the array to be sorted.
2nd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
2nd Parameter
The number of elements in the array.
3rd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
3rd Parameter
The size in bytes of each element in the array.
4th Parameter Type : int (*)(const void *, const void *)
Pointer to a function that takes two constant void pointers as arguments and returns an integer, typically used to compare two elements.
4th Parameter
Pointer to a comparison function that determines the order of elements. It takes two `const void *` arguments and returns a negative, zero, or positive value based on the comparison.
Read more about parameters of qsort in parameters section
The qsortfunction in C language Sorts an array of elements using the quicksort algorithm.
The qsort function implements a quick sort algorithm to sort an array of any type. It sorts the array in-place, and uses a comparison function provided by the caller to determine the order of elements. This function is highly efficient and widely used for sorting arrays of various data types.
The qsortfunction takes 4
parameters:
•
void * `base`: Pointer to the base of the array to be sorted.
•
size_t `num`: The number of elements in the array.
•
size_t `size`: The size in bytes of each element in the array.
•
int (*)(const void *, const void *) `compar`: Pointer to a comparison function that determines the order of elements. It takes two `const void *` arguments and returns a negative, zero, or positive value based on the comparison.
Performs a quicksort on the array pointed to by `base`, sorting `num` elements of size `size` bytes each. The comparison function `compar` is used to define the order of the elements. This function does not return a value, and the array is sorted in place.
The qsort function return value :
This function does not return a value
Output
This example demonstrates how to use qsort to sort an array of integers in ascending order. It defines a comparison function that determines the order of elements.