- 作用
给数组分配空间,并初始化为0, 与memset类似
void *calloc(
size_t num,
size_t size
);
- 应用
// crt_calloc.c
// This program uses calloc to allocate space for
// 40 long integers. It initializes each element to zero.
#include <stdio.h>
#include <malloc.h>
int main( void )
{
long *buffer;
buffer = (long *)calloc( 40, sizeof( long ) );
if( buffer != NULL )
printf( "Allocated 40 long integers\n" );
else
printf( "Can't allocate memory\n" );
free( buffer );
}