1. qsort() 快速排序函数调用
#include<stdlib.h>
void qsort(void *base, size_t n_elements, size_t el_size, int (*compare)(const void *, const void *));
其中第一个参数为数组首地址,第二个参数为数组长度,第三个参数为每个元素的类型长度,第四个参数为需要实现的比较函数地址。
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int a[] = {2, 3, 1, 5, 4};
int i;
qsort(a, 5, sizeof(int), cmp);
for(i=0; i<5; i++)
{
putchar(a[i]+'0');
putchar('\n');
}
return 0;
}
2. 指针数组与数组指针
#include <stdio.h>
int main()
{
int a[2][2] = {
{1,2},{3,4}};
int (*p)[2]; // 数组指针,可以这样赋值p=a,不能是p=a[]
char *s[2] = {"hello", "world"}; // 指针数组,是一维数组
p = a;
printf("%d, %d, %d, %d\n", (*p)[0