qsort () explain

Jun 28, 2011 at 8:43pm
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?

Jun 28, 2011 at 8:50pm
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 Jun 28, 2011 at 8:51pm
Jun 28, 2011 at 8:58pm
thanks a lot
Topic archived. No new replies allowed.