Mechanism of __c in structure in C language

Source: Internet
Author: User
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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.