C++ Programming/Code/Standard C Library/Functions/calloc
< C++ Programming < Code < Standard C Library < Functionscalloc
Syntax |
#include <cstdlib>
void *calloc( size_t num, size_t size);
|
The function calloc() allocates a block of memory that can store an array of num cells, each with a size size. Every cell of the array is set to value zero.
If the operation fails, calloc() returns "NULL".
EXAMPLE:
ptr = (float*)calloc(25, sizeof(float));
/* It would create an array of 25 cells, each one with a size of 4 bytes
“(sizeof(float))”, all the cells initialized with value 0 */
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.