<stdlib.h> C Standard Library

The stdlib.h header file includes several general purpose utility functions, including string conversion, dynamic memory management, Integer arithmetic, system commands, random number generation, searching and sorting etc.

List of stdlib.h Library Functions

Click on function names below to see detailed description of functions.

Function Description
abort Abort current program at the point of call.
abs Returns the absolute value of integer.
atexit Sets a function to be executed on program termination.
atof Converts a string to floating point number(double).
atoi Converts a string to an integer number(int).
atol Converts a string to a long integer number.
bsearch Performs binary search in a sorted array.
calloc Allocates a memory block and initialize it with zero.
div Returns quotient and remainder of integer division.
exit Terminates the calling program normally.
free Deallocate memory block previously allocated by calloc, malloc, or realloc.
getenv Searches for the environment variable whose name is passed as argument.
labs Returns the absolute value long integer.
ldiv Returns quotient and remainder of long integer division.
malloc Allocates a memory block and returns a pointer to it.
qsort Sorts elements of an array.
rand Generate pseudo random number in range of 0 to RAND_MAX.
realloc Reallocates a memory block and returns a pointer to it.
srand Initialize random number generator used by rand function.
strtod Converts a string to a double and return remaining string.
strtol Converts a string to a long integer and return remaining string.
strtoul Converts a string to a unsigned long integer and return remaining string.
system Execute system command in host environment.

Macros Defined in stdlib.h Library

Macro Description
NULL Null pointer constant
EXIT_FAILURE This value is used in exit function to represent abnormal termination of program due to failure
EXIT_SUCCESS This value is used in exit function to represent success termination of program
EXIT_SUCCESS This value is used in exit function to represent success termination of program
RAND_MAX Maximum value returned by rand function
MB_CUR_MAX Maximum number of bytes in a multi-byte character

Data Types in stdlib.h Library

Types Description
div_t Structure returned by the div function.
ldiv_t Structure returned by the ldiv function.
size_t Unsigned integral type.
wchar_t A typedef of an integral type of the size of a wide character constant.