C Tutorial/stdlib.h/calloc — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
(нет различий)
|
Текущая версия на 10:32, 25 мая 2010
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);
}
}