0% found this document useful (0 votes)
59 views

C - Library - Stdlib

Uploaded by

trgykl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

C - Library - Stdlib

Uploaded by

trgykl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/30/2018 C Library <stdlib.

h>

C Library - <stdlib.h>
Advertisements

 Previous Page Next Page 

The stdlib.h header defines four variable types, several macros, and various functions for performing general functions.

Library Variables
Following are the variable types defined in the header stdlib.h −

Sr.No. Variable & Description

size_t
1
This is the unsigned integral type and is the result of the sizeof keyword.

wchar_t
2
This is an integer type of the size of a wide character constant.

div_t 
3
This is the structure returned by the div function.

ldiv_t
4
This is the structure returned by the ldiv function.

Library Macros
Following are the macros defined in the header stdlib.h −

Sr.No. Macro & Description

NULL
1
This macro is the value of a null pointer constant.

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

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

RAND_MAX
4
This macro is the maximum value returned by the rand function.

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

Library Functions
Following are the functions defined in the header stdio.h −

Sr.No. Function & Description

double atof(const char *str)


1 Converts the string pointed to, by the argument str to a floating-point number (type double).

https://www.tutorialspoint.com/c_standard_library/stdlib_h.htm 1/3
1/30/2018 C Library <stdlib.h>

int atoi(const char *str)


2 Converts the string pointed to, by the argument str to an integer (type int).

long int atol(const char *str)


3 Converts the string pointed to, by the argument str to a long integer (type long int).

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


4 Converts the string pointed to, by the argument str to a floating-point number (type double).

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


5 Converts the string pointed to, by the argument str to a long integer (type long int).

unsigned long int strtoul(const char *str, char **endptr, int base)
6 Converts the string pointed to, by the argument str to an unsigned long integer (type unsigned long int).

void *calloc(size_t nitems, size_t size)


7 Allocates the requested memory and returns a pointer to it.

void free(void *ptr


8 Deallocates the memory previously allocated by a call to calloc, malloc, or realloc.

void *malloc(size_t size)


9 Allocates the requested memory and returns a pointer to it.

void *realloc(void *ptr, size_t size)


10 Attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc.

void abort(void)
11 Causes an abnormal program termination.

int atexit(void (*func)(void))


12 Causes the specified function func to be called when the program terminates normally.

void exit(int status)


13 Causes the program to terminate normally.

char *getenv(const char *name)


14 Searches for the environment string pointed to by name and returns the associated value to the string.

int system(const char *string)


15 The command specified by string is passed to the host environment to be executed by the command processor.

void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))
16 Performs a binary search.

void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))
17 Sorts an array.

int abs(int x)
18 Returns the absolute value of x.

div_t div(int numer, int denom)


19 Divides numer (numerator) by denom (denominator).

long int labs(long int x)


20 Returns the absolute value of x.

ldiv_t ldiv(long int numer, long int denom)


21 Divides numer (numerator) by denom (denominator).

int rand(void)
22 Returns a pseudo-random number in the range of 0 to RAND_MAX.

void srand(unsigned int seed)


23 This function seeds the random number generator used by the function rand.

https://www.tutorialspoint.com/c_standard_library/stdlib_h.htm 2/3
1/30/2018 C Library <stdlib.h>
24 int mblen(const char *str, size_t n)
Returns the length of a multibyte character pointed to by the argument str.

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


25 Converts the string of multibyte characters pointed to by the argument str to the array pointed to by pwcs.

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


26 Examines the multibyte character pointed to by the argument str.

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


27 Converts the codes stored in the array pwcs to multibyte characters and stores them in the string str.

int wctomb(char *str, wchar_t wchar)


28 Examines the code which corresponds to a multibyte character given by the argument wchar.

 Previous Page Next Page 

Advertisements

Tutorials Point (India) Pvt. Ltd.

YouTube 38B

Write for us FAQ's Helping Contact


© Copyright 2018. All Rights Reserved.

Enter email for newsletter go

https://www.tutorialspoint.com/c_standard_library/stdlib_h.htm 3/3

You might also like