In stdlib.h, there is a declaration of the function qsort() with prototype:
void qsort( void *ptr, size_t count, size_t size,
int (*comp)(const void *, const void *) );
Obviously it is a generic programming.
I wonder how it implement, how to get the element from the void * type?
void *pointers are casted according to thesize_t size(the 3rd argument inqsort)First we typecast the
void*tochar*and then do pointer arithmetic according to thesize(because char takes1byte so adding the size will give correct pointer arithmetic )EDIT : (for in built data types)
e.g.
NOTE : size is implementation defined so it may vary to compilers