#include <stdio.h>
#include <malloc.h>
struct student {
int age;
};
struct data {
int len;
// 不占用空间
struct student students[0];
};
int main() {
struct data* d = malloc(sizeof(struct data) + 2 * sizeof(struct student));
d->len = 2;
d->students[0].age = 10;
d->students[1].age = 11;
// 结果是4
printf("%d\n", sizeof(struct data));
// 内存对齐,结果是8
printf("%d\n", sizeof(d));
// 结果是0
printf("%d\n", sizeof(d->students));
free(d);
return 0;
}
标签:struct,students,C语言,int,数组,printf,sizeof,data,不定
From: https://www.cnblogs.com/WJQ2017/p/17914776.html