初学指针
(void *)ptr 和 (*(void**))ptr的结果是否相同?其中ptr为同一个指针为什么啊?
/* qsort.c: Illustrates qsort */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comp(const void*, const void*);
int main()
{
char* strings[] =
{"how", "now", "brown", "cow"};
const unsigned int nstr =
sizeof strings / sizeof strings[0];
unsigned int i;
qsort(strings, nstr, sizeof strings[0], comp);
for (i = 0; i < nstr; ++i)
puts(strings[i]);
return 0;
}
int comp(const void* p1, const void* p2)
{
char* a = *(char **) p1;
char* b = *(char **) p2;
return strcmp(a,b);
}