C++ Standard Library C++ STL Library
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C++ - <cstdlib> (stdlib.h)



The C++ <cstdlib> header defines several general purpose functions which includes dynamic memory management, random number generation, communication with the environment, integer arithmetics, searching, sorting and converting.

Library Functions

Numeric string conversion functions

FunctionsDescription
atoi() Converts a byte string to an integer value.
atol() Converts a byte string to a long integer value.
atoll() Converts a byte string to a long long integer value.

Dynamic memory management functions

FunctionsDescription
calloc() Allocate and zero-initialize array.
free() Deallocates previously allocated memory.
malloc() Allocates memory.
realloc() Reallocates previously allocated memory block.

Pseudo-random sequence generation functions

FunctionsDescription
rand() Returns a pseudo-random integral value between 0 and RAND_MAX.
srand() Seeds the pseudo-random number generator used by rand() with the value seed.

Integer arithmetics functions

FunctionsDescription
abs() Returns absolute value of an integral value.
div() Returns quotient and remainder of integer division.
labs() Returns absolute value of an integral value.
ldiv() Returns quotient and remainder of integer division.
llabs() Returns absolute value of an integral value.
lldiv() Returns quotient and remainder of integer division.

Library Types

TypesDescription
div_t Structure type, return by div() function.
ldiv_t Structure type, return by ldiv() function.
lldiv_t Structure type, return by lldiv() function.
size_t Unsigned integer type.

Library Macros

Macro constants

MacrosDescription
MB_CUR_MAX Maximum size of a multibyte characters with the current locale.
NULL Null pointer.
RAND_MAX Maximum value returned by rand() function.

5