C language Seventh: structural body

Source: Internet
Author: User

1. Structure declaration:

struct struct body name {

type specifier member name;

...

type specifier member name;

};

Structs, arrays are constructed from basic data types, and arrays are data types constructed from the same basic data types, and structs can be constructed from different basic data types. Structs are more flexible than arrays.

Access struct member: struct variable. struct Member name

The assignment of struct variables: STU1 = STU2 is directly assigned;

Based on this feature, the overall assignment of the array can be accomplished with the help of the struct.

The memory allocation principle of the structure body:

1. Open space according to the largest data type of the member of the struct, and continue to open up space according to the maximum number of bytes when the allocated space is insufficient;

2. Allocate according to the second largest data type of the number of bytes in the struct member;

3. If the allocation is surplus, no longer occupied.

Structure function:

1. Custom data types (constructed types) that can be used to define variables

2. Struct is a large container, flexible than array, can store variables of different data types

C language Seventh: structural body

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.