- 论坛徽章:
- 0
|
- void *calloc(
- size_t num,
- size_t size
- );
复制代码
Allocates an array in memory with elements initialized to 0.
Parameters
num
Number of elements.
size
Length in bytes of each element.
Return Value
calloc returns a pointer to the allocated space. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.
- /* 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 );
- }
复制代码
[ 本帖最后由 westgarden 于 2006-3-29 16:58 编辑 ] |
|