int comparator(const void p, const void q)
{
return (((int)p) -(*(int *)b));
}
qsort(a,6,sizeof(int),comparator);
in the above standard library function qsort can someone explain what will be the value of p and q in comparator function.thanks in advance.
The arguments should correctly be written as:
int comparator(const void *a, const void *b)
The arguments point to the starting of the data. Since we are using void *, the compiler needs to know how many bytes to look into starting from the address of argument. And hence, it is typecasted to whatever type we want.