C Standard Library - <stdlib.h>
Introduction
The stdlib.h header file defines four variable types, several macros, and various general-purpose utility functions.
Library Variables
The following variable types are defined in the stdlib.h header file:
No. | Variable & Description |
---|---|
1 | size_t <br>This is an unsigned integer type, the result of the sizeof keyword. |
2 | wchar_t <br>This is an integer type of the size of a wide character constant. |
3 | div_t <br>This is the structure returned by the div function. |
4 | ldiv_t <br>This is the structure returned by the ldiv function. |
Library Macros
The following macros are defined in the stdlib.h header file:
No. | Macro & Description |
---|---|
1 | NULL <br>This macro is the value of a null pointer constant. |
2 | EXIT_FAILURE <br>This is the value to return from the exit function in case of failure. |
3 | EXIT_SUCCESS <br>This is the value to return from the exit function in case of success. |
4 | RAND_MAX <br>This macro is the maximum value returned by the rand function. |
5 | MB_CUR_MAX <br>This macro represents the maximum number of bytes in a multibyte character set, which cannot be greater than MB_LEN_MAX. |
Library Functions
The following functions are defined in the stdlib.h header file:
No. | Function & Description |
---|---|
1 | double atof(const char *str) <br>Converts the string pointed to by str to a floating-point number (type double). |
2 | int atoi(const char *str) <br>Converts the string pointed to by str to an integer (type int). |
3 | long int atol(const char *str) <br>Converts the string pointed to by str to a long integer (type long int). |
4 | double strtod(const char str, char *endptr) <br>Converts the string pointed to by str to a floating-point number (type double). |
5 | long int strtol(const char str, char *endptr, int base) <br>Converts the string pointed to by str to a long integer (type long int). |
6 | unsigned long int strtoul(const char str, char *endptr, int base) <br>Converts the string pointed to by str to an unsigned long integer (type unsigned long int). |
7 | void *calloc(size_t nitems, size_t size) <br>Allocates the requested memory and returns a pointer to it. |
8 | void free(void *ptr) <br>Deallocates the memory previously allocated by a call to calloc, malloc, or realloc. |
9 | void *malloc(size_t size) <br>Allocates the requested memory and returns a pointer to it. |
10 | void *realloc(void *ptr, size_t size) <br>Attempts to resize the memory block pointed to by ptr that was previously allocated with malloc or calloc. |
11 | void abort(void) <br>Causes an abnormal program termination. |
12 | int atexit(void (*func)(void)) <br>Registers the function func to be called on normal program termination. |
13 | void exit(int status) <br>Causes normal program termination. |
14 | char *getenv(const char *name) <br>Searches for the environment string pointed to by name and returns the associated value to the string. |
15 | int system(const char *string) <br>Passes the command specified by string to the host environment to be executed by the command processor. |
16 | void bsearch(const void *key, const void *base, size_t nitems, size_t size, int (compar)(const void *, const void *)) <br>Performs a binary search. |
17 | void qsort(void base, size_t nitems, size_t size, int (compar)(const void , const void)) <br>Sorts an array. |
18 | int abs(int x) <br>Returns the absolute value of x. |
19 | div_t div(int numer, int denom) <br>Divides the numerator by the denominator. |
20 | long int labs(long int x) <br>Returns the absolute value of x. |
21 | ldiv_t ldiv(long int numer, long int denom) <br>Divides the numerator by the denominator. |
22 | int rand(void) <br>Returns a pseudo-random number in the range of 0 to RAND_MAX. |
23 | void srand(unsigned int seed) <br>Seeds the random number generator used by the function rand. |
24 | int mblen(const char *str, size_t n) <br>Returns the length of the multibyte character pointed to by str. |
25 | size_t mbstowcs(schar_t *pwcs, const char *str, size_t n) <br>Converts the multibyte character string pointed to by str to the array pointed to by pwcs. |
26 | int mbtowc(whcar_t *pwc, const char *str, size_t n) <br>Examines the multibyte character pointed to by str. |
27 | size_t wcstombs(char *str, const wchar_t *pwcs, size_t n) <br>Converts the code stored in the array pwcs to multibyte characters and stores them in the string str. |
28 | int wctomb(char *str, wchar_t wchar) <br>Examines the code corresponding to the multibyte character given by wchar. |