C Programming

CALLOC
This function is used to allocate storage to a variable whilst the program is running. The function takes two arguments that specify the number of elements to be reserved, and the size of each element (obtained from sizeof) in bytes. The function returns a character pointer (void in ANSI C) to the allocated storage, which is initialized to zero's.


	struct date *date_pointer;

	date_pointer = (struct date *)  calloc( 10, sizeof(struct date) );

The (struct date *) is a type cast operator which converts the pointer returned from calloc to a character pointer to a structure of type date. The above function call will allocate size for ten such structures, and date_pointer will point to the first in the chain.


©Copyright B Brown. 1984-1999. All rights reserved.