Stdlib.h
From Wikipedia, the free encyclopedia
C++ Standard Library headers |
C Standard Library headers |
---|
assert.h |
complex.h |
ctype.h |
errno.h |
fenv.h |
float.h |
inttypes.h |
iso646.h |
limits.h |
locale.h |
math.h |
setjmp.h |
signal.h |
stdarg.h |
stdbool.h |
stddef.h |
stdint.h |
stdio.h |
stdlib.h |
string.h |
tgmath.h |
time.h |
wchar.h |
wctype.h |
- The correct title of this article is stdlib.h. The initial letter is shown capitalized due to technical restrictions.
stdlib.h is the header of the general purpose standard library of C programming language which includes functions involving memory allocation, process control, conversions and others. It is compatible with C++ and is known as cstdlib
in C++.
Contents |
[edit] Member functions
The name "stdlib" stands for standard library. Members of the stdlib.h
can be classified into the following categories: conversion, memory, process control, sort and search, mathematics.
Name | Description |
---|---|
Type Conversion | |
atof |
string to float |
atoi |
string to integer |
atol |
string to long integer |
strtod |
string to double |
strtol |
string to long int |
strtoul |
string to unsigned long int |
Pseudo-random sequence generation | |
rand |
generate a pseudo-random value |
srand |
set the pseudo-random generator seed |
Memory allocation and deallocation | |
malloc calloc realloc |
allocate memory from the heap |
free |
release memory back to the heap |
Process control | |
abort |
terminate execution abnormally |
atexit |
register a callback function for program exit |
exit |
terminate program execution |
getenv |
retrieve an environment variable |
system |
execute an external command |
Sorting and searching | |
bsearch |
binary search an array |
qsort |
sort an array |
Mathematics | |
abs labs |
absolute value |
div ldiv |
integer division |
[edit] Member constants
The stdlib.h
and stddef.h
header files define the macro NULL, which yields a null pointer constant, and represents a pointer value that is guaranteed not to point to a valid address in memory. NULL may be defined as a constant expression equal to int zero, long int zero, or zero cast to a void * pointer:
#define NULL 0
#define NULL 0L
#define NULL ((void *) 0)
Note: Although the null pointer constant is always represented in C by the symbolic constant 0 or by 0 cast to a void pointer, the actual bit representation of such a pointer is system-specific and might not be all-bits-zero.
[edit] Member data types
A datatype called size_t
is defined in the stdlib.h
library, which represents sizes of an array in the member functions of the library. In practice, size_t
is often assumed to have the same storage requirements as an unsigned integer. Because the actual size of size_t
is architecture-dependent, this assumption can lead to programming errors, particularly as 64-bit architectures become more prevalent.
Two less widely used datatypes, div_t
and ldiv_t
, are also defined. They are the return types of the div and ldiv functions. The standard defines them as:
typedef struct { int quot, rem; } div_t;
typedef struct { long int quot, rem; } ldiv_t;
[edit] Nonstandard functions
itoa is a common function that is included in many implementations of stdlib.h, but the standard does not define the function. It may have been included because of its appearance in The C Programming Language.
[edit] See also
[edit] References
- stdlib.h summary on cplusplus.com, accessed in February 2006.