calloc

来自cppreference.com
< c | memory

Defined in header <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.

[编辑] 注釋

由於對齊的要求,分配的位元組數不一定等於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.

[编辑] 另請參閱