Stdlib.h

From Wikipedia, the free encyclopedia

C++ Standard Library headers
C Standard Library headers
assert.h
ctype.h
errno.h
float.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdarg.h
stddef.h
stdio.h
string.h
stdlib.h
time.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

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
strtol
strtoul
Pseudo-random sequence generation
rand
srand
Memory allocation and deallocation
calloc, malloc, and realloc
free
Process control
abort
atexit
exit
getenv
system
Sorting and searching
bsearch
qsort
Mathematics
abs, labs Absolute value
div, ldiv

[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 either 0, 0L, or (void *) 0:

#define NULL 0
#define NULL 0L
#define NULL ((void *) 0)

Note: Although the null pointer constant is always represented in C by the integer 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

In other languages