C Library –

C Library – <stdlib.h> ”; Previous Next 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 1 size_t This is the unsigned integral type and is the result of the sizeof keyword. 2 wchar_t This is an integer type of the size of a wide character constant. 3 div_t This is the structure returned by the div function. 4 ldiv_t 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 1 NULL This macro is the value of a null pointer constant. 2 EXIT_FAILURE This is the value for the exit function to return in case of failure. 3 EXIT_SUCCESS This is the value for the exit function to return in case of success. 4 RAND_MAX This macro is the maximum value returned by the rand function. 5 MB_CUR_MAX 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 stlib.h − Sr.No. Function & Description 1 double atof(const char *str) Converts the string pointed to, by the argument str to a floating-point number (type double). 2 int atoi(const char *str) Converts the string pointed to, by the argument str to an integer (type int). 3 long int atol(const char *str) Converts the string pointed to, by the argument str to a long integer (type long int). 4 double strtod(const char *str, char **endptr) Converts the string pointed to, by the argument str to a floating-point number (type double). 5 long int strtol(const char *str, char **endptr, int base) Converts the string pointed to, by the argument str to a long integer (type long int). 6 unsigned long int strtoul(const char *str, char **endptr, int base) Converts the string pointed to, by the argument str to an unsigned long integer (type unsigned long int). 7 void *calloc(size_t nitems, size_t size) Allocates the requested memory and returns a pointer to it. 8 void free(void *ptr Deallocates the memory previously allocated by a call to calloc, malloc, or realloc. 9 void *malloc(size_t size) Allocates the requested memory and returns a pointer to it. 10 void *realloc(void *ptr, size_t size) Attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc. 11 void abort(void) Causes an abnormal program termination. 12 int atexit(void (*func)(void)) Causes the specified function func to be called when the program terminates normally. 13 void exit(int status) Causes the program to terminate normally. 14 char *getenv(const char *name) Searches for the environment string pointed to by name and returns the associated value to the string. 15 int system(const char *string) The command specified by string is passed 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 *)) Performs a binary search. 17 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)) Sorts an array. 18 int abs(int x) Returns the absolute value of x. 19 div_t div(int numer, int denom) Divides numer (numerator) by denom (denominator). 20 long int labs(long int x) Returns the absolute value of x. 21 ldiv_t ldiv(long int numer, long int denom) Divides numer (numerator) by denom (denominator). 22 int rand(void) Returns a pseudo-random number in the range of 0 to RAND_MAX. 23 void srand(unsigned int seed) This function seeds the random number generator used by the function rand. 24 int mblen(const char *str, size_t n) Returns the length of a multibyte character pointed to by the argument str. 25 size_t mbstowcs(schar_t *pwcs, const char *str, size_t n) Converts the string of multibyte characters pointed to by the argument str to the array pointed to by pwcs. 26 int mbtowc(whcar_t *pwc, const char *str, size_t n) Examines the multibyte character pointed to by the argument str. 27 size_t wcstombs(char *str, const wchar_t *pwcs, size_t n) Converts the codes stored in the array pwcs to multibyte characters and stores them in the string str. 28 int wctomb(char *str, wchar_t wchar) Examines the code which corresponds to a multibyte character given by the argument wchar. Print Page Previous Next Advertisements ”;

C Library –

C Library – <stdarg.h> ”; Previous Next The stdarg.h header defines a variable type va_list and three macros which can be used to get the arguments in a function when the number of arguments are not known i.e. variable number of arguments. A function of variable arguments is defined with the ellipsis (,…) at the end of the parameter list. Library Variables Following is the variable type defined in the header stdarg.h − Sr.No. Variable & Description 1 va_list This is a type suitable for holding information needed by the three macros va_start(), va_arg() and va_end(). Library Macros Following are the macros defined in the header stdarg.h − Sr.No. Macro & Description 1 void va_start(va_list ap, parmN) This macro enables access to variadic function arguments. 2 type va_arg(va_list ap, type) This macro retrieves the next argument in the parameter list of the function with type type. 3 void va_end(va_list ap) This macro allows to end traversal of the variadic function arguments. 4 void va_copy( va_list dest, va_list src ) This macro makes a copy of the variadic function arguments. Print Page Previous Next Advertisements ”;

C Library – Quick Guide

C Standard Library – Quick Guide ”; Previous Next C Library – <assert.h> The assert.h header file of the C Standard Library provides a macro called assert which can be used to verify assumptions made by the program and print a diagnostic message if this assumption is false. The defined macro assert refers to another macro NDEBUG which is not a part of <assert.h>. If NDEBUG is defined as a macro name in the source file, at the point where <assert.h> is included, the assert macro is defined as follows − #define assert(ignore) ((void)0) Library Macros Following is the only function defined in the header assert.h − Sr.No. Function & Description 1 void assert(int expression) This is actually a macro and not a function, which can be used to add diagnostics in your C program. C Library – <ctype.h> The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the functions return non-zero (true) if the argument c satisfies the condition described, and zero(false) if not. Library Functions Following are the functions defined in the header ctype.h − Sr.No. Function & Description 1 int isalnum(int c) This function checks whether the passed character is alphanumeric. 2 int isalpha(int c) This function checks whether the passed character is alphabetic. 3 int iscntrl(int c) This function checks whether the passed character is control character. 4 int isdigit(int c) This function checks whether the passed character is decimal digit. 5 int isgraph(int c) This function checks whether the passed character has graphical representation using locale. 6 int islower(int c) This function checks whether the passed character is lowercase letter. 7 int isprint(int c) This function checks whether the passed character is printable. 8 int ispunct(int c) This function checks whether the passed character is a punctuation character. 9 int isspace(int c) This function checks whether the passed character is white-space. 10 int isupper(int c) This function checks whether the passed character is an uppercase letter. 11 int isxdigit(int c) This function checks whether the passed character is a hexadecimal digit. The library also contains two conversion functions that accepts and returns an “int”. Sr.No. Function & Description 1 int tolower(int c) This function converts uppercase letters to lowercase. 2 int toupper(int c) This function converts lowercase letters to uppercase. Character Classes Sr.No. Character Class & Description 1 Digits This is a set of whole numbers { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }. 2 Hexadecimal digits This is the set of { 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f }. 3 Lowercase letters This is a set of lowercase letters { a b c d e f g h i j k l m n o p q r s t u v w x y z }. 4 Uppercase letters This is a set of uppercase letters {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }. 5 Letters This is a set of lowercase and uppercase letters. 6 Alphanumeric characters This is a set of Digits, Lowercase letters and Uppercase letters. 7 Punctuation characters This is a set of ! ” # $ % & ” ( ) * + , – . / : ; < = > ? @ [ ] ^ _ ` { | } ~ 8 Graphical characters This is a set of Alphanumeric characters and Punctuation characters. 9 Space characters This is a set of tab, newline, vertical tab, form feed, carriage return, and space. 10 Printable characters This is a set of Alphanumeric characters, Punctuation characters and Space characters. 11 Control characters In ASCII, these characters have octal codes 000 through 037, and 177 (DEL). 12 Blank characters These are spaces and tabs. 13 Alphabetic characters This is a set of Lowercase letters and Uppercase letters. C Library – <errno.h> The errno.h header file of the C Standard Library defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong. This macro expands to a modifiable lvalue of type int, therefore it can be both read and modified by a program. The errno is set to zero at program startup. Certain functions of the standard C library modify its value to other than zero to signal some types of error. You can also modify its value or reset to zero at your convenience. The errno.h header file also defines a list of macros indicating different error codes, which will expand to integer constant expressions with type int. Library Macros Following are the macros defined in the header errno.h − Sr.No. Macro & Description 1 extern int errno This is the macro set by system calls and some library functions in the event of an error to indicate what went wrong. 2 EDOM Domain Error This macro represents a domain error, which occurs if an input argument is outside the domain, over which the mathematical function is defined and errno is set to EDOM. 3 ERANGE Range Error This macro represents a range error, which occurs if an input argument is outside the range, over which the mathematical function is defined and errno is set to ERANGE. C Library – <float.h> The float.h header file of the C Standard Library contains a set of various platform-dependent constants related to floating point values. These constants are proposed by ANSI C. They allow making more portable programs. Before checking all the constants, it is good to understand that floating-point number is composed of following four elements − Sr.No. Component & Component Description 1 S sign ( +/- ) 2 b base or

C Library – Discussion

Discuss C Standard Library ”; Previous Next C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the Unix operating system. C is the most widely used computer language, that keeps fluctuating at number one scale of popularity along with Java programming language which is also equally popular and most widely used among modern software programmers. The C Standard Library is a set of C built-in functions, constants and header files like <stdio.h>, <stdlib.h>, <math.h>, etc. This library will work as a reference manual for C programmers. Print Page Previous Next Advertisements ”;

C Library – Useful Resources

C Standard Library – Useful Resources ”; Previous Next The following resources contain additional information on C Standard Library. Please use them to get more in-depth knowledge on this. Useful Video Courses STL – Standard Template Library in C++ : Data Structures 15 Lectures 1 hours Anant Rungta More Detail VMware vSphere 7: install, configure, manage [v7] VCTA 2021 Featured 109 Lectures 8 hours TAL Mohamed More Detail Indian Accounting Standards (Ind AS) Certificate Training 58 Lectures 41 hours Uplatz More Detail International Accounting Standards (AS) Certificate 2023 31 Lectures 18.5 hours Uplatz More Detail Candlestick Patterns & Analysis A-Z Masterclass 19 Lectures 1 hours Travis Rose More Detail Adobe After Effects Ultimate guide 2022 169 Lectures 6 hours Learn Tech Plus More Detail Print Page Previous Next Advertisements ”;

C Library –

C Library – <stddef.h> ”; Previous Next The stddef.h header defines various variable types and macros. Many of these definitions also appear in other headers. Library Variables Following are the variable types defined in the header stddef.h − Sr.No. Variable & Description 1 ptrdiff_t This is the signed integral type and is the result of subtracting two pointers. 2 size_t This is the unsigned integral type and is the result of the sizeof keyword. 3 wchar_t This is an integral type of the size of a wide character constant. Library Macros Following are the macros defined in the header stddef.h − Sr.No. Macro & Description 1 NULL This macro is the value of a null pointer constant. 2 offsetof(type, member-designator) This results in a constant integer of type size_t which is the offset in bytes of a structure member from the beginning of the structure. The member is given by member-designator, and the name of the structure is given in type. Print Page Previous Next Advertisements ”;

C Library –

C Library – <stdalign.h> ”; Previous Next The stdalign.h header file is part of the standard C library. It defines macros related to alignment and allows us to query and specify the alignment of object in our C programs. C − stdalign.h Operators Following is the operator defined in the header stdalign.h − Sr.No. Operator & Description 1 alignof(type) This helps us to determine the alignment of a type or an expression. Print Page Previous Next Advertisements ”;

C Library –

C Library – <fenv.h> ”; Previous Next The fenv.h header file is part of the standard C library, defines various functions and macros for manipulating the floating-point environment. It allows us to control aspects related to floating-point arithmetic, like exception handling and rounding modes. C − fenv.h Types Following are the types defined in the header fenv.h − Sr.No. Types & Description 1 fenv_t This type represents the entire floating-point environment. 2 fexcept_t This type represents all floating-point status flags collectively. Library Functions Following are the functions defined in the header fenv.h − Sr.No. Function & Description 1 int feclearexcept( int excepts ) This function clears the specified floating-point status flags. 2 int fetestexcept( int excepts ) This function determines which of the specified floating-point status flags are set. 3 int feraiseexcept(int excepts) This function raises the specified floating-point exceptions. 4 int fegetexceptflag( fexcept_t* flagp, int excepts ) This function retrieves the full contents of the floating-point exception flags. 5 int fesetexceptflag(const fexcept_t *flagp, int excepts) This function sets the contents of the floating-point exception flags. 6 int fegetround() This function retrieves the rounding direction. 7 int fesetround( int round ) This function sets the rounding direction. 8 int fegetenv( fenv_t* envp ) This function attempts to store the status of the floating-point environment in the object pointed to by envp. 9 int fesetenv( const fenv_t* envp ) This function attempts to establish the floating-point environment from the object pointed to by envp. 10 int feholdexcept( fenv_t* envp ) This function saves the environment, clears all status flags and ignores all future errors. 11 int feupdateenv( const fenv_t* envp ) This function restores the floating-point environment and raises the previously raise exceptions. Print Page Previous Next Advertisements ”;

C Library –

C Library – <math.h> ”; Previous Next The math.h header defines various mathematical functions and one macro. All the functions available in this library take double as an argument and return double as the result. Library Macros There is only one macro defined in this library − Sr.No. Macro & Description 1 HUGE_VAL This macro is used when the result of a function may not be representable as a floating point number. If magnitude of the correct result is too large to be represented, the function sets errno to ERANGE to indicate a range error, and returns a particular, very large value named by the macro HUGE_VAL or its negation (- HUGE_VAL). If the magnitude of the result is too small, a value of zero is returned instead. In this case, errno might or might not be set to ERANGE. Library Functions Following are the functions defined in the header math.h − Sr.No. Function & Description 1 double acos(double x) Returns the arc cosine of x in radians. 2 double asin(double x) Returns the arc sine of x in radians. 3 double atan(double x) Returns the arc tangent of x in radians. 4 double atan2(double y, double x) Returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant. 5 double cos(double x) Returns the cosine of a radian angle x. 6 double cosh(double x) Returns the hyperbolic cosine of x. 7 double sin(double x) Returns the sine of a radian angle x. 8 double sinh(double x) Returns the hyperbolic sine of x. 9 tan(double x) Returns the tangent of a given angle(x). 10 double tanh(double x) Returns the hyperbolic tangent of x. 11 double exp(double x) Returns the value of e raised to the xth power. 12 double frexp(double x, int *exponent) The returned value is the mantissa and the integer pointed to by exponent is the exponent. The resultant value is x = mantissa * 2 ^ exponent. 13 double ldexp(double x, int exponent) Returns x multiplied by 2 raised to the power of exponent. 14 double log(double x) Returns the natural logarithm (base-e logarithm) of x. 15 double log10(double x) Returns the common logarithm (base-10 logarithm) of x. 16 double modf(double x, double *integer) The returned value is the fraction component (part after the decimal), and sets integer to the integer component. 17 double pow(double x, double y) Returns x raised to the power of y. 18 double sqrt(double x) Returns the square root of x. 19 double ceil(double x) Returns the smallest integer value greater than or equal to x. 20 double fabs(double x) Returns the absolute value of x. 21 double floor(double x) Returns the largest integer value less than or equal to x. 22 double fmod(double x, double y) Returns the remainder of x divided by y. 23 double round(double x) Returns the nearest integer value of x(rounded off values). Print Page Previous Next Advertisements ”;

C Library –

C Library – <ctype.h> ”; Previous Next The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the functions return non-zero (true) if the argument c satisfies the condition described, and zero(false) if not. Library Functions Following are the functions defined in the header ctype.h − Sr.No. Function & Description 1 int isalnum(int c) This function checks whether the passed character is alphanumeric. 2 int isalpha(int c) This function checks whether the passed character is alphabetic. 3 int iscntrl(int c) This function checks whether the passed character is control character. 4 int isdigit(int c) This function checks whether the passed character is decimal digit. 5 int isgraph(int c) This function checks whether the passed character has graphical representation using locale. 6 int islower(int c) This function checks whether the passed character is lowercase letter. 7 int isprint(int c) This function checks whether the passed character is printable. 8 int ispunct(int c) This function checks whether the passed character is a punctuation character. 9 int isspace(int c) This function checks whether the passed character is white-space. 10 int isupper(int c) This function checks whether the passed character is an uppercase letter. 11 int isxdigit(int c) This function checks whether the passed character is a hexadecimal digit. 12 int isblank(int c) This function checks whether the passed character is a blank character. The library also contains two conversion functions that accepts and returns an “int”. Sr.No. Function & Description 1 int tolower(int c) This function converts uppercase letters to lowercase. 2 int toupper(int c) This function converts lowercase letters to uppercase. Character Classes Sr.No. Character Class & Description 1 Digits This is a set of whole numbers { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }. 2 Hexadecimal digits This is the set of { 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f }. 3 Lowercase letters This is a set of lowercase letters { a b c d e f g h i j k l m n o p q r s t u v w x y z }. 4 Uppercase letters This is a set of uppercase letters {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }. 5 Letters This is a set of lowercase and uppercase letters. 6 Alphanumeric characters This is a set of Digits, Lowercase letters and Uppercase letters. 7 Punctuation characters This is a set of ! ” # $ % & ” ( ) * + , – . / : ; < = > ? @ [ ] ^ _ ` { | } ~ 8 Graphical characters This is a set of Alphanumeric characters and Punctuation characters. 9 Space characters This is a set of tab, newline, vertical tab, form feed, carriage return, and space. 10 Printable characters This is a set of Alphanumeric characters, Punctuation characters and Space characters. 11 Control characters In ASCII, these characters have octal codes 000 through 037, and 177 (DEL). 12 Blank characters These are spaces and tabs. 13 Alphabetic characters This is a set of Lowercase letters and Uppercase letters. Print Page Previous Next Advertisements ”;