函数指针练习
函数指针练习
h>
#include <stdlib.h>
#include <time.h>
#if 0
typedef int (*func)(int, int);
int main(void)
{
int (*p)(int, int) = max;
int a = 2;
int b = 3;
#if 0
void populate_array(int *array, size_t arraySize, int (*getNextValue)(void))
{
for (size_t i = 0; i < arraySize; i++)
{
array[i] = getNextValue();
}
}
int getNextRandomValue(void)
{
return rand();
}
int main(void)
{
int myArray[10];
srand(time(0));
populate_array(myArray, 10, getNextRandomValue);
return 0;
}
#endif
}
}
}
int main(void)
{
Student s1 = { "Jade", 25, 80 };
Student s2 = { "paul", 26, 78 };
Student s3 = { "mike", 21, 88 };
Student stuArray[3] = { s1, s2, s3 };
SortStudent(stuArray, 3, CmpByAge);
PrintStu(stuArray, 3);
SortStudent(stuArray, 3, CmpByScore);
PrintStu(stuArray, 3);
}