Question: qsort is a function used for sorting arrays of any type. In order for this to work a comparator function must be given that defines

qsort is a function used for sorting arrays of any type. In order for this to work a comparator function must be given that defines what makes a value greater than, less than or equal to another value. The prototype for qsort is as follows:

void qsort ( void * base, size_t num, size_t size,

int ( * comparator ) ( const void *, const void * ) );

Parameters represent the starting location, number of elements, size of an element, and comparator function.

Suppose that you have an array of struct x_struct called, say, xarray[50]. You wish to sort the array using qsort. Naturally, you will need some type of comparison function to decide how two elements are related; either the first is less than the second, equal to the second, or greater than the second. Unfortunately you cannot just tell qsort to use memcmp as the comparison function. Why not? Give a syntactical reason and a logical reason.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!