C programming stdlib.h header


The C <stdlib.h> header defines some types and several functions for general utility and some macros.The lists of all the types and macros and functions are given below.

Types

There are only five types found in the header file.

size_tThis type is same as unsigned int type
wchar_tA wide character type type
div_tA structure of the type return by ‘div’ function.
ldiv_tA structure of the type return by ‘ldiv’.
lldiv_tA structure of the type return by ‘lldiv function’

Macros

NULLThe value 0.
EXIT_FAILURE1
EXIT_SUCCESS0
RAND_MAXMaximum integer value returned by ‘rand’ function.
MB_CUR_MAXMaximum number of bytes in multi-byte character in the current locale and never greater than MB_LEN_MAX.

FUNCTIONS

Return
type
Function name and
argument
Function definition

Numeric conversion
doubleatof(const char*)Converts string to double type.
int
long int
long long
atoi(const char*)
atol(const char*)
atoll(const char*)
Converts string to int ,long int and long long.
double
float
long double
strtod(const char *,char **)
strtof(const char *,char **)
strtold(const char *,char **)
Converts string to double,float and long double
long int
long long int
unsigned long int
unsigned long long
strtol(const char *,char **,int)
strtoll(const char *,char **,int)
strtoul(const char *,char **,int)
strtoull(const char *,char **,int)
Converts string to long int,longlong,unsigned long ,unsigned long long

Pseudo-random sequence
generation
intrand(void)Generate random number
voidsrand(unsigned int)Uses seed to generate random number

Memory management
void *calloc(size_t , size_t)Allocate memory
voidfree(void *)Frees the memory using the pointer passed
void *malloc(size_t)Allocate memory of size passed as argument
void *realloc(void *, size_t)Deallocate old memory and return a pointer to new memory

Communication with
the environment
voidabort(void)Terminate program
intatexit(void (*)(void))registers the function pointed by the argument
voidexit(int )Terminate the program
void_Exit(int status)(C++11)Terminate the program
char * getenv(const char *)searches an environment list
intsystem(const char *)Determines whether the environment has a command processor

Searching sorting
utilities
void *bsearch(const void *, const void *,size_t , size_t , int (*)(const void *, const void *) )Searches an array
voidqsort(void *, size_t , size_t , int (*)(const void *, const void *))Sorts an array

Integer arithmetic
int
long int
long long int
abs(int)
labs(long int)
llabs(long long int)
Compute absolute value of the argument
div_t
ldiv_t
lldiv_t
div(int , int)
ldiv(long int, long int)
lldiv(long long int numer, long long int denom)
(C++11)
compute the quotient and remainder

wide/multibyte
character conversion
intmblen(const char *s, size_t n)Determines the number of bytes contained in the multibyte character
intmbtowc(wchar_t * restrict ,const char * restrict , size_t )inspects bytes to determine the number of bytes needed to complete the next multibyte character
intwctomb(char *, wchar_t )Determines the number of bytes needed to represent the multibyte character of the wide character

Multibyte/wide
string conversion
size_tmbstowcs(wchar_t * restrict, const char * restrict , size_t) converts a sequence of multibyte characters into a sequence of corresponding wide characters
size_twcstombs(char * restrict ,const wchar_t * restrict , size_t)converts a sequence of wide characters into a sequence of multibyte characters