Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to expand the space of dynamic array in C language
How to expand the space of dynamic array in C language
C language dynamic array expansion space is mainly realized by using dynamic storage allocation library functions, such as malloc function and calloc function.

Malloc () is one of a set of standard library functions for dynamic storage management in C language. Its function is to allocate a continuous space with the length of size in the dynamic storage area of memory. Its parameter is an unsigned integer, and the return value is a pointer to the starting address of the allocated continuous storage domain.

For example:

char * x;

x =(char *)malloc( 10); //x points to a storage space containing 10 character units.

Extended data:

function definition

Its function prototype is void *malloc (unsigned int size); ); Its function is to allocate a continuous space with the length of size in the dynamic storage area of memory. The return value of this function is the starting address of the allocation area, or this function is a pointer function, and the returned pointer points to the starting position of the allocation area.

If the allocation is successful, return a pointer to the allocated memory (the initial value of this storage area is uncertain), otherwise return a null pointer. When the memory is no longer used, the free () function should be used to release the memory block. The pointer returned by the function must be properly aligned so that it can be used for any data object.

Baidu encyclopedia -malloc function