cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
qsort () explain
qsort () explain
Jun 28, 2011 at 8:43pm UTC
Anon777
(55)
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 UTC
LB
(13399)
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 UTC
Jun 28, 2011 at 8:58pm UTC
Anon777
(55)
thanks a lot
Topic archived. No new replies allowed.