Structure s
{
char c;
char arr[2];
};
s s 1;
float f = 1. 1;
sizeof(float)=4,sizeof(f)= 4;
//sizeof(struct S) is the total size of all members of the calculation type struct S, that is, Sizeof (c)+Sizeof (arr) =1+2 = 3.
sizeof(struct S)= 3;
//Because the size of a variable is equal to the size of its type, sizeof (s1) = sizeof (structures) = 3.
sizeof(s 1)= 3;
2.malloc is a library function. Malloc (size); The function of is to allocate a memory of size in the heap, and then return the first address of this memory block, but it returns a void* pointer, so it is necessary to type the return value. For example:
int * pint =(int *)malloc(sizeof(int));
//Suppose the first address is 100, and the heap memory addresses that pointer ps can use are 100,10, 102 (because sizeof(struct S)=3, malloc allocates 3 bytes of memory).
//and ps points to the first address 100.
struct S * PS =(struct S *)malloc(sizeof(struct S));
3. Memory allocated with malloc must be released with free (pointer variable name), which is another library function. For example:
//release the above structure through structures * PS = (structures *) malloc (size of (structures)); 3 bytes of memory allocated by the statement.
Free (PS);
Understand the above three points, your code is not difficult to understand.