C language dynamic memory management

One: dynamic memory management

write picture description here

Two: flexible array:

1. Statement:

struct A
{
    int i;
    int arr[];//不指定数组大小
};

2. Flexible array features:

(1) A flexible array member in a structure must be preceded by at least one other member.
(2) The size of the structure returned by sizeof does not include the memory of the flexible array.
(3) The structure containing flexible array members uses the malloc() function to dynamically allocate memory, and the allocated memory should be larger than the size of the structure to accommodate the expected size of the flexible array.

3. Advantages of flexible arrays:

(1) It is convenient for memory release
(2) This is beneficial to the access speed

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325944738&siteId=291194637