mechanism of structure internal storage and distribution in C language
the principle of memory allocation follows: (1): The size of the allocated memory space must be a multiple of 4
(2): The size of the memory space allocated for each type of type specifier (Char,int,float,double,long) in the structure is consistent with the largest byte of the type descriptor (for example, the longest type of byte in the structure is long. The memory allocated by each type is consistent with long.
(3): If the allocated memory space is larger than the current type of bytes, then the type complement (if the following is the int type, then int in the address space can be divisible by 4).
Direct examples to illustrate:
Structural body
typedef struct student{
Long age;
char sex;
float Score;
char s;
int D;
}student;
The above structure body allocates 24 bytes of memory space
(1) First long allocates 8 bytes of space to store a long variable, (2) then allocate 8 bytes of space for Char, but the char type occupies only one type space (3) so there will be 7 bytes of space left, then the remaining byte space is filled by the float type variable, which is added to the place divisible by 4, (4) then assign 8 bytes (5) to a variable of type char and the remaining byte is filled in the fourth byte space by a variable of type int