Skip to content
C stdlib.h
Functions
String Functions
- atof()
- Converts a string to a double-precision floating-point number, stopping at the first non-numeric character.
- atoi()
- Converts a string to an integer, stopping at the first non-numeric character. Deprecated in favor of
strtol()
for better error handling.
- atol()
- Converts a string to a long integer, stopping at the first non-numeric character.
- atoll()
- Converts a string to a long long integer, stopping at the first non-numeric character.
- strtod()
- Converts a string to a double-precision floating-point number, providing better error handling than
atof()
.
- strtof()
- Converts a string to a single-precision floating-point number (float), stopping at the first invalid character.
- strtol()
- Converts a string to a long integer with support for different numerical bases and error handling.
- strtold()
- Converts a string to a long double floating-point number, providing higher precision than
strtod()
.
- strtoll()
- Converts a string to a long long integer, supporting different numerical bases and error handling.
- strtoul()
- Converts a string to an unsigned long integer, supporting different numerical bases and error handling.
- strtoull()
- Converts a string to an unsigned long long integer, supporting different numerical bases and error handling.
Random Sequence Generation Functions
- rand()
- Generates a pseudo-random integer in the range
0
to RAND_MAX
, using a linear congruential generator.
- srand()
- Seeds the random number generator with a specified value, allowing
rand()
to produce different sequences of random numbers.
Dynamic Memory Management Functions
- calloc()
- Allocates memory for an array of elements, initializes all bytes to zero, and returns a pointer to the allocated memory.
- free()
- Deallocates a previously allocated memory block, freeing up system memory.
- malloc()
- Allocates a specified number of bytes in memory and returns a pointer to the allocated block. The memory is uninitialized.
- realloc()
- Resizes a previously allocated memory block while preserving its contents if possible. If a new block is allocated, the old data is copied.
Environment Functions
- abort()
- Immediately terminates the calling process abnormally, without executing cleanup functions or flushing streams.
- atexit()
- Registers a function to be executed when
exit()
is called, useful for cleanup operations.
- at_quick_exit()
- Registers a function to be executed when
quick_exit()
is called, similar to atexit()
but used for faster termination.
- exit()
- Terminates the calling process normally, performing cleanup functions such as closing open file streams.
- getenv()
- Retrieves the value of an environment variable as a string, allowing access to system configuration data.
- quick_exit()
- Terminates the calling process quickly, executing functions registered with
at_quick_exit()
but skipping some cleanup operations.
- system()
- Executes a system command by passing a string to the host environment’s command processor.
- _Exit()
- Terminates the calling process immediately, skipping cleanup functions and flushing of output streams.
Searching and Sorting Functions
- bsearch()
- Performs a binary search on a sorted array, returning a pointer to the matching element if found, or
NULL
if not found.
- qsort()
- Sorts an array using the quicksort algorithm, requiring a user-defined comparison function to determine element order.
Integer Arithmetic Functions
- abs()
- Returns the absolute value of an integer, ensuring the result is always non-negative.
- div()
- Performs integer division and returns a structure containing both the quotient and remainder.
- labs()
- Returns the absolute value of a long integer.
- ldiv()
- Performs division on long integers and returns a structure containing both the quotient and remainder.
- llabs()
- Returns the absolute value of a long long integer.
- lldiv()
- Performs division on long long integers and returns a structure containing both the quotient and remainder.
Multibyte Characters Functions
- mblen()
- Determines the number of bytes in a multibyte character, given the current locale.
- mbtowc()
- Converts a multibyte character sequence into a wide character, based on the current locale.
- wctomb()
- Converts a wide character into its corresponding multibyte sequence.
Multibyte Strings Functions
- mbstowcs()
- Converts a multibyte character string into a wide-character string, based on the current locale.
- wcstombs()
- Converts a wide-character string into a multibyte character string, based on the current locale.