23.9.1.calloc |
|
Item | Value | Header file | stdlib.h | Declaration | void *calloc(size_t num, size_t size); | Function | allocates sufficient memory for an array of num objects of size size. | Return | returns a pointer to the first byte of the allocated region. |
|
If there is not enough memory to satisfy the request, a null pointer is returned. |
All bits in the allocated memory are initially set to zero. |
It is important to verify that the return value is not null before attempting to use it. |
Return a pointer to a dynamically allocated array of 100 floats: |
#include <stdlib.h>
#include <stdio.h>
int main(void){
float *p;
p = calloc(100, sizeof(float));
if(!p) {
printf("Allocation Error\n");
exit(1);
}
}
|
|