多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# C 标准库 - <stdlib.h> ## 简介 **stdlib .h** 头文件定义了四个变量类型、一些宏和各种通用工具函数。 ## 库变量 下面是头文件 stdlib.h 中定义的变量类型: | 变量 | 描述 | | --- | --- | | **size_t** | 这是无符号整数类型,它是 **sizeof** 关键字的结果。 | | **wchar_t** | 这是一个宽字符常量大小的整数类型。 | | **div_t** | 这是 **div** 函数返回的结构。 | | **ldiv_t** | 这是 **ldiv** 函数返回的结构。 | ## 库宏 下面是头文件 stdlib.h 中定义的宏: | 宏 | 描述 | | --- | --- | | **NULL** | 这个宏是一个空指针常量的值。 | | **EXIT_FAILURE** | 这是 exit 函数失败时要返回的值。 | | **EXIT_SUCCESS** | 这是 exit 函数成功时要返回的值。 | | **RAND_MAX** | 这个宏是 rand 函数返回的最大值。 | | **MB_CUR_MAX** | 这个宏表示在多字节字符集中的最大字符数,不能大于 MB_LEN_MAX。 | ## 库函数 下面是头文件 stdlib.h 中定义的函数: | 函数 | 描述 | | --- | --- | | [double atof(const char \*str)](c-function-atof.html) | 把参数 _str_ 所指向的字符串转换为一个浮点数(类型为 double 型)。 | | [int atoi(const char \*str)](c-function-atoi.html) | 把参数 _str_ 所指向的字符串转换为一个整数(类型为 int 型)。 | | [long int atol(const char \*str)](c-function-atol.html) | 把参数 _str_ 所指向的字符串转换为一个长整数(类型为 long int 型)。 | | [double strtod(const char \*str, char \*\*endptr)](c-function-strtod.html) | 把参数 _str_ 所指向的字符串转换为一个浮点数(类型为 double 型)。 | | [long int strtol(const char \*str, char \*\*endptr, int base)](c-function-strtol.html) | 把参数 _str_ 所指向的字符串转换为一个长整数(类型为 long int 型)。 | | [unsigned long int strtoul(const char \*str, char \*\*endptr, int base)](c-function-strtoul.html) | 把参数 _str_ 所指向的字符串转换为一个无符号长整数(类型为 unsigned long int 型)。 | | [void \*calloc(size_t nitems, size_t size)](c-function-calloc.html) | 分配所需的内存空间,并返回一个指向它的指针。 | | [void free(void \*ptr](c-function-free.html) | 释放之前调用 _calloc、malloc_ 或 _realloc_ 所分配的内存空间。 | | [void \*malloc(size_t size)](c-function-malloc.html) | 分配所需的内存空间,并返回一个指向它的指针。 | | [void \*realloc(void \*ptr, size_t size)](c-function-realloc.html) | 尝试重新调整之前调用 _malloc_ or _calloc_ 所分配的 ptr 所指向的内存块的大小。 | | [void abort(void)](c-function-abort.html) | 使一个异常程序终止。 | | [int atexit(void (\*func)(void))](c-function-atexit.html) | 当程序正常终止时,调用指定的函数 \*\*func\*\*。 | | [void exit(int status)](c-function-exit.html) | 是程序正常终止。 | | [char \*getenv(const char \*name)](c-function-getenv.html) | 搜索 name 所指向的环境字符串,并返回相关的值给字符串。 | | [int system(const char \*string)](c-function-system.html) | 由 string 指定的命令传给要被命令处理器执行的主机环境。 | | [void \*bsearch(const void \*key, const void \*base, size_t nitems, size_t size, int (\*compar)(const void \*, const void \*))](c-function-bsearch.html) | 执行二进制搜索。 | | [void qsort(void \*base, size_t nitems, size_t size, int (\*compar)(const void \*, const void\*))](c-function-qsort.html) | 数组排序。 | | [int abs(int x)](c-function-abs.html) | 返回 x 的绝对值。 | | [div_t div(int numer, int denom)](c-function-div.html) | 分子除以分母。 | | [long int labs(long int x)](c-function-labs.html) | 返回 x 的绝对值。 | | [ldiv_t ldiv(long int numer, long int denom)](c-function-ldiv.html) | 分子除以分母。 | | [int rand(void)](c-function-rand.html) | 返回一个范围在 0 到 _RAND_MAX_ 之间的伪随机数。 | | [void srand(unsigned int seed)](c-function-srand.html) | 该函数播种由函数 \*\*rand\*\* 使用的随机数发生器。 | | [int mblen(const char \*str, size_t n)](c-function-mblen.html) | 返回参数 _str_ 所指向的多字节字符的长度。 | | [size_t mbstowcs(schar_t \*pwcs, const char \*str, size_t n)](c-function-mbstowcs.html) | 把参数 _str_ 所指向的多字节字符的字符串转换为参数 _pwcs_ 所指向的数组。 | | [int mbtowc(whcar_t \*pwc, const char \*str, size_t n)](c-function-mbtowc.html) | 检查参数 _str_ 所指向的多字节字符。 | | [size_t wcstombs(char \*str, const wchar_t \*pwcs, size_t n)](c-function-wcstombs.html) | 把数组 _pwcs_ 中存储的编码转换为多字节字符,并把它们存储在字符串 _str_ 中。 | | [int wctomb(char \*str, wchar_t wchar)](c-function-wctomb.html) | 检查对应于参数 _wchar_ 所给出的多字节字符的编码。 |