C++ cstdlib header library

The C++ <ctsdlib> header file is similar to the C <stdlib.h> header file.This file includes several macros and functions which is made available to the user for their varied and wide practical uses.

The list of all the macros and functions included under the <cstdlib> header file is given below.To use the macro or the function include ‘<cstdlib>‘ in your program.


There are only three types found in the header file.

div_tA structure of the type return by ‘div’ function.
ldiv_tA structure of the type return by ‘ldiv’.
lldiv_t(C++11)A structure of the type return by ‘lldiv function’


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.


Function name and
Function definition

Numeric conversion
doubleatof(const char*)Converts string to double type.
long int
long long
atoi(const char*)
atol(const char*)
atoll(const char*)
Converts string to int ,long int and long long.
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
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
intat_quick_exit(void (*f)(void)) (C++11)register the function pointed to 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
voidquick_exit(int)(C++11)Functions registered by calls to at_quick_exit are called in the reverse order
intsystem(const char *)Determines whether the environment has a command processor

Searching sorting
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
long int
long long int
labs(long int)
llabs(long long int)
Compute absolute value of the argument
div(int , int)
ldiv(long int, long int)
lldiv(long long int numer, long long int denom)
compute the quotient and remainder

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

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