Пространства имён
Варианты
Действия

calloc

Материал из cppreference.com
< c | memory

Заголовочный файл <stdlib.h>
void* calloc( size_t num, size_t size );
Выделяет память для массива num объекты размером size и нулевой инициализирует его.
Original:
Allocates memory for an array of num objects of size size and zero-initializes it.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если выделение успешно, возвращает указатель на самой низкой (первой) байт в выделенный блок памяти, который соответствующим выровнены для любого типа объектов.
Original:
If allocation succeeds, returns a pointer to the lowest (first) byte in the allocated memory block that is suitably aligned for any object type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если size равна нулю, то поведение определяется реализацией (нулевого указателя могут быть возвращены, или некоторые не нулевой указатель может быть возвращен, которая не может быть использован для доступа к памяти)
Original:
If size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

num -
количество объектов
Original:
number of objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
size -
Размер каждого объекта
Original:
size of each object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Возвращаемое значение

Указатель на начало новой выделенной памяти или NULL, если произошла ошибка. Указатель должен быть освобожден с free().
Original:
Pointer to the beginning of newly allocated memory or NULL if error has occurred. The pointer must be deallocated with free().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Notes

В связи с выравниванием требования, количество выделенных байт не обязательно равна num*size.
Original:
Due to the alignment requirements, the number of allocated bytes is not necessarily equal to num*size.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] См. также