// 柔性数组
// 柔性数组的特点:柔性数组的成员数量是动态的.
// 存在于结构体中,最后一个成员,未知的成员数量。
// 特点: 柔性数组前面至少有一个成员,sizeof 计算结构体大小,不包含柔性数组成员。
// 包含柔性数组的结构,用malloc 进行内存的动态分配,并且的内存应该大于结构的大小,以适应柔性数组的预期大小。// struct S {
// int a;
// int b;
// int c[]; // 未知大小,柔性数组成员 或者写成 int c[0];
// };
//
// int main() {
// struct S *ps = (struct S*)malloc(sizeof(struct S) + 10 * sizeof(int));
// if (ps == NULL) {
// perror("malloc()");
// return 1;
// }
// // 访问
// ps->a = 10;
// ps->b = 20;
// for (int i = 0; i < 10; i++) {
// ps->c[i] = i+1;
// printf("%d\n", ps->c[i]);
// }
// // 调整大小
// struct S * newp = (struct S*)realloc(ps, sizeof(struct S) + 20 * sizeof(int));
// if (newp == NULL) // 如果调整失败为空
// {
// perror("realloc()");
// newp = NULL;
// return 1;
// }
// for (int i = 10; i < 20; i++) {
// ps->c[i] = i+1;
// printf("%d\n", ps->c[i]);
// }
// free(ps);
// ps = NULL;
// // free(newp);
// // newp = NULL;
// return 0;
// }