In C, the array size is fixed and has no variable length, and in order to achieve an array of variable lengths, a 0-length array is provided in such a way as to define a struct body:
struct Test
{
int length;
Char contents[0];
In this way, the structure itself length =sizeof (int), that is, an integer length, contents is not space, and then in the program call, you can use the following:
struct Test *t = (struct test*) malloc (sizeof (struct Test) +);
T->length = 10;
So this time, T occupies the space is sizeof (struct Test) + 10, the extra space just can have t->contents to point to, and the length of the array is t->length, so you can get to the dynamic array;
But there are drawbacks to this, which is that 0-length arrays can be used for heap space, but not for stack space, that is, if struct test test; By this definition, the length of test is OK, and contents cannot be allocated by the program to get extra space, that is, at this time, the length of the test is just sizeof (struct test), which is the size of the sizeof (int).