Programming in C

(Barry) #1
Dynamic Memory Allocation Functions 481

A pointer to the character that terminated the scan is stored inside the character
pointer pointed to by end,provided endis not a null pointer.
long double strtold (s, end)
Is like strtod, except converts its argument to long double.
long long int strtoll (s, end, base)
Is like strtol, except a long long intis returned.
unsigned long int strtoul (s, end, base)
Converts sto unsigned long int,returning the result.The remaining arguments are
interpreted as for strtol.
unsigned long long int strtoull (s, end, base)
Converts sto unsigned long long int,returning the result.The remaining argu-
ments are interpreted as for strtol.

Dynamic Memory Allocation Functions
The following functions are available for allocating and freeing memory dynamically. For
each of these functions,nand sizerepresent integers of type size_t,and pointerrep-
resents a voidpointer.To use these functions, include the following line in your pro-
gram:
#include <stdlib.h>

void *calloc (n, size)
Allocates contiguous space for nitems of data, where each item is sizebytes in
length.The allocated space is initially set to all zeroes. On success, a pointer to the
allocated space is returned; on failure, the null pointer is returned.
void free (pointer)
Returns a block of memory pointed to by pointerthat was previously allocated by a
calloc,malloc, or realloccall.
void *malloc (size)
Allocates contiguous space of sizebytes, returning a pointer to the beginning of the
allocated block if successful, and the null pointer otherwise.
void *realloc (pointer, size)
Changes the size of a previously allocated block to sizebytes, returning a pointer to
the new block (which might have moved), or a null pointer if an error occurs.

21 0672326663 AppB 6/10/04 2:03 PM Page 481

Free download pdf