What is a flexible array?

Source: Internet
Author: User

C99 Medium

The last element in the structure can be an array of unknown sizes. This is called a flexible array member.

However, there must be at least one other member before the flexible array in the structure. The flexible array member allows the structure to contain a variable-size array.

The size of the structure returned by sizeof does not include the memory of the flexible array.

The malloc function is used to dynamically allocate memory for structures containing soft array members, and the allocated memory should be larger than the structure size to adapt to the expected size of the flexible array.

How to use flexible Arrays: Example:

Typedef struct st_type

{

Int I; int A [0];

} Type_a;

Some compilers report errors and cannot be changed:

Typedef struct st_type

{

Int I; int A [];

} Type_a;

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.