stdlib.h in C

The header file named stdlib.h in Standard C Library defines four variable types, a number of macros and various functions to implement common features.

stdlib.h in C

The header file named stdlib.h in Standard C Library defines four variable types, a number of macros and various functions to implement common features.

The variables are defined in stdlib.h

The following lists some types of variables defined in stdlib.h:

Description variable size_t

This is an unsigned integer type and the result of the sizeof keyword

wchar_t

This is an integer type whose size is a constant wide char

div_t

This is the structure returned by the div function

ldiv_t

This is the structure returned by the ldiv function

The macros are defined in stdlib.h

The table below lists some macros defined in stdlib.h:

Macro Description NULL

This macro is the value of a null pointer constant

EXIT_FAILURE

This is the value for exit function to return in case of failure

EXIT_SUCCESS

This is the value for exit function to return in case of success

RAND_MAX

This macro is the maximum value returned by the rand function

MB_CUR_MAX

This macro is the maximum number of bytes in a multi-byte character set that cannot be larger than MB_LEN_MAX

Functions are defined in stdlib.h

Here are some functions defined in stdio.h:

STD & Description1

Double atof function (const char * str)

Convert a string pointed to by parameter str to a floating point number (type double)

2

Int atoi function (const char * str)

Convert a string pointed to by parameter str to an integer (type int)

3

Function long int atol (const char * str)

Convert a string pointed to by parameter str to some long int

4

Function double strtod (const char * str, char ** endptr)

Convert a string pointed to by parameter str to a floating point number (type double)

5

Function long int strtol (const char * str, char ** endptr, int base)

Convert a string pointed to by parameter str to some long int

6

Function unsigned long int strtoul (const char * str, char ** endptr, int base)

Converts a string pointed to by parameter str to an unsigned number long int

7

Function void * calloc (size_t nitems, size_t size)

Memory allocation is required and returns a pointer to it

8

Void free function (void * ptr

Free the previously allocated memory by a call to calloc, malloc, or realloc

9

Function void * malloc (size_t size)

Memory allocation is required and returns a pointer to it

ten

Void * realloc function (void * ptr, size_t size)

Attempt to recover the memory block pointed to by str that was previously allocated with a call to malloc or calloc

11

Void abort function (void)

Causing an abnormal program end

twelfth

Int atexit function (void (* func) (void))

Make the func function given to be called when the program ends in the usual way

13

Function void exit (int status)

Make the program end normally

14

Char * getenv function (const char * name)

Search for the environment string pointed to by name and return the value associated with that string

15

Function int system (const char * string)

The command specified by the string is passed to the host environment to be executed by the Command Processor

16

Void function * bsearch (const void * key, const void * base, size_t nitems, size_t size, int (* compar) (const void *, const void *))

Make a Binary Search

17

Void qsort function (void * base, size_t nitems, size_t size, int (* compar) (const void *, const void *))

Arrange an array

18

Int abs function (int x)

Returns the absolute value of x

19

Div_t div function (int numer, int denom)

Divide the numerator numer to the demon number

20

Function long int labs (long int x)

Returns the absolute value of x

21

Ldiv_t ldiv function (long int numer, long int denom)

Divide the numerator numer to the demon number

22

Function int rand (void)

Returns a random number in the range of values ​​from 0 to RAND_MAX

23

Function void srand (unsigned int seed)

This function provides seed for the random number generator used by the rand function

24

Function int mblen (const char * str, size_t n)

Returns the length of a multi-byte char pointed to by parameter str

25

Function size_t mbstowcs (schar_t * pwcs, const char * str, size_t n)

Convert the string of multi-byte char points pointed to by the parameter str to the array pointed to by pwcs

26

Function int mbtowc (whcar_t * pwc, const char * str, size_t n)

Convert a multi-byte sequence into a wide char

27

Function size_t wcstombs (char * str, const wchar_t * pwcs, size_t n)

Convert the code stored in the pwcs array into multi-byte char and store them in the string str

28

Int wctomb function (char * str, wchar_t wchar)

Convert its wide char to a multi-byte char representation and store it at the beginning of the character array pointed to by str

According to Tutorialspoint

Previous lesson: Function of perror () in C

Next lesson: Atof () function in C

5 ★ | 1 Vote