Arrays that are dynamically established during program operation rather than through array descriptions are called dynamic arrays; to create dynamic arrays, you must use
Library functions in
malloc
and
free
to allocate and free memory units; for example to create a
double
A dynamic array of types must first explain a pointer
double
Pointer to the object:
double * pd;
Then create the required size from the following statement (e.g.
100
) memory space and let the pointer point to this space:
pd = (double ) malloc(100*sizeof(double))
. When there is no sufficient connected memory, allocation fails and return a null pointer
(NULL,0)
。