我们先来看一段C程序,如下:
#include <stdio.h>
#include <stdlib.h>
int MyCompare(const void *elem1, const void *elem2)
{
unsigned int *p1, *p2;
p1 = (unsigned int *)elem1;
p2 = (unsigned int *)elem2;
return (*p1%10) - (*p2%10);
}
#define NUM 18
int main()
{
unsigned int an[NUM]={6,7,5,4,3,2,1,9,8,11,13,14,12,19,17,16,15,18};
qsort(an,NUM,sizeof(unsigned int), MyCompare);
for( int i = 0; i < NUM; i++ )
{
print("%d",an[i]);
}
return 0;
}
如果你能看懂上段程序,则你不必问谷歌何是函数指针。