qsort () explain

I do not understand qsort I have already read http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/

This is the third paarmeter of qsort function :

1
2
3
4
int f (const void *a,const void *b)
{
    return *(int*) a - *(int*) b;
}


I do not understand this code:
*(int*) a - *(int*) b

Can someone explain this to me please?

It casts the void pointers a and b to int pointers, dereferences them, and then subtracts one from the other. Note that subtraction-based comparators don't work as well as comparators that actually compare.
Last edited on
thanks a lot
Topic archived. No new replies allowed.