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 – <iso646_h.h> ”; Previous Next The C library header <iso646_h.htm> allows the alternative operators such as and, xor, not, etc which return the specific value. For example, using “and” instead of && in boolean expressions can make the code more readable. There are eleven macros which are derieved from the header iso646.h − Macro Token and && and_eq &= bitand & bitor | compl ˜ not ! not_eq != or || or_eq |= xor ^ xor_eq ^= Example Following is the C library header <iso646_h.htm> to see the demonstration of two number using alternative(”and”) operator. #include <stdio.h> #include <iso646.h> int main() { int a = 5; int b = 3; // Using the alternative ”and” operator int sum = a and b; printf(“Sum of %d and %d = %dn”, a, b, sum); return 0; } Output The above code produces the following result − Sum of 5 and 3 = 1 Example We create a program for swapping two numbers using alternative operators(xor). #include <stdio.h> #include <iso646.h> int main() { int x = 5; int y = 3; // Using the alternative ”xor” operator x = x xor y; y = x xor y; x = x xor y; printf(“After swapping: x = %d, y = %dn”, x, y); return 0; } Output On execution of above code, we get the following result − After swapping: x = 3, y = 5 Example Below the program calculate the logical “and” of two values using alternative operator. #include <stdio.h> #include <iso646.h> int main() { int bool1 = 1; int bool2 = 0; int result = bool1 and bool2; printf(“Logical AND of %d and %d = %dn”, bool1, bool2, result); return 0; } Output After executing the code, we get the following result − Logical AND of 1 and 0 = 0 Print Page Previous Next Advertisements ”;

C Library –

C Library – <float.h> ”; Previous Next The C Library float.h header file contains a set of various platform-dependent constants related to floating point values. These constants are proposed by ANSI C. The float macros allow developers to create more portable programs. Before proceeding with all the constants, it is better to understand the floating-point number which consist following four elements − Sr.No. Component & Component Description 1 S sign ( +/- ) 2 b The base or radix of the exponent representation, 2 for binary, 10 for decimal, 16 for hexadecimal, and so on… 3 e Exponent, an integer between a minimum emin and a maximum emax. 4 p The precision is a number of base-b digits in the significand. Based on the above 4 components, a floating point will have its value as follows − floating-point = ( S ) p x be or floating-point = (+/-) precision x baseexponent Library Macros The following values are implementation-specific and defined with the #define directive, but these values may not be any lower than what is given here. Note that in all instances FLT refers to type float, DBL refers to double, and LDBL refers to long double. Sr.No. Macro & Description 1 FLT_ROUNDS Defines the rounding mode for floating point addition and it can have any of the following values − -1 − indeterminable 0 − towards zero 1 − to nearest 2 − towards positive infinity 3 − towards negative infinity 2 FLT_RADIX 2 This defines the base radix representation of the exponent. A base-2 is binary, base-10 is the normal decimal representation, base-16 is Hex. 3 FLT_MANT_DIG DBL_MANT_DIG LDBL_MANT_DIG These macros define the number of digits in the number (in the FLT_RADIX base). 4 FLT_DIG 6 DBL_DIG 10 LDBL_DIG 10 These macros define the maximum number decimal digits (base-10) that can be represented without change after rounding. 5 FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP These macros define the minimum negative integer value for an exponent in base FLT_RADIX. 6 FLT_MIN_10_EXP -37 DBL_MIN_10_EXP -37 LDBL_MIN_10_EXP -37 These macros define the minimum negative integer value for an exponent in base 10. 7 FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP These macros define the maximum integer value for an exponent in base FLT_RADIX. 8 FLT_MAX_10_EXP +37 DBL_MAX_10_EXP +37 LDBL_MAX_10_EXP +37 These macros define the maximum integer value for an exponent in base 10. 9 FLT_MAX 1E+37 DBL_MAX 1E+37 LDBL_MAX 1E+37 These macros define the maximum finite floating-point value. 10 FLT_EPSILON 1E-5 DBL_EPSILON 1E-9 LDBL_EPSILON 1E-9 These macros define the least significant digit representable. 11 FLT_MIN 1E-37 DBL_MIN 1E-37 LDBL_MIN 1E-37 These macros define the minimum floating-point values. Example 1 Following is the C Library header file float.h to define the values of few macros(float) constant. #include <stdio.h> #include <float.h> int main () { printf(“The maximum value of float = %.10en”, FLT_MAX); printf(“The minimum value of float = %.10en”, FLT_MIN); printf(“The number of digits in the number = %.10dn”, FLT_MANT_DIG); } Output After executing the above code, we get the following result − The maximum value of float = 3.4028234664e+38 The minimum value of float = 1.1754943508e-38 The number of digits in the number = 7.2996655210e-312 Example 2 Following is the C Library header file float.h to define the values of few macros(float) constant. #include <stdio.h> #include <float.h> int main () { printf(“The maximum value of float = %.10en”, FLT_MAX); printf(“The minimum value of float = %.10en”, FLT_MIN); printf(“The number of digits in the number = %.10dn”, FLT_MANT_DIG); } Output After executing the above code, we get the following result − The maximum value of float = 3.4028234664e+38 The minimum value of float = 1.1754943508e-38 The number of digits in the number = 1.1754943508e-38 Example 3 Below the program uses the macros(FLT_RADIX) to measure the value of base exponents. #include <stdio.h> #include <float.h> int main() { // Get the value of FLT_RADIX int radix = FLT_RADIX; printf(“The base (radix) of the exponent representation: %dn”, radix); return 0; } Output The above code produces the following output − The base (radix) of the exponent representation: 2 Example 4 Here, we define the three different macros which are FLT_MAX, DBL_MAX, and LDBL_MAX that calculates the number of banayan needed to stack up to Mount Everest’s height using banayan lengths. #include <stdio.h> #include <float.h> int main() { // Heights in inches double heightOfEverestInFeet = 29031.7; double heightOfEverestInInches = heightOfEverestInFeet * 12.0; // Banana length (FLT_MAX, DBL_MAX, and LDBL_MAX are all approximately 1E+37) double banayanLength = 1E+37; // Calculate the number of bananas needed double numBanayan = heightOfEverestInInches / banayanLength; printf(“Height of Mount Everest: %.2lf feetn”, heightOfEverestInFeet); printf(“Length of a magical banayan: %.2lf inchesn”, banayanLength); printf(“Number of bananas needed to reach the summit: %.2e banayann”, numBanayan); return 0; } Output On execution of above code, we get the following output − Height of Mount Everest: 29031.70 feet Length of a magical banayan: 9999999999999999538762658202121142272.00 inches Number of bananas needed to reach the summit: 3.48e-32 banayan 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 – Home

C Standard Library Reference Tutorial PDF Version Quick Guide Resources Job Search Discussion 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. Audience The C Standard Library is a reference for C programmers to help them in their projects related to system programming. All the C functions have been explained in a user-friendly way and they can be copied and pasted in your C projects. Prerequisites A basic understanding of the C Programming language will help you in understanding the C built-in functions covered in this library. 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 ”;

C Library –

C Library – <setjmp.h> ”; Previous Next The setjmp.h header defines the macro setjmp(), one function longjmp(), and one variable type jmp_buf, for bypassing the normal function call and return discipline. Library Variables Following is the variable type defined in the header setjmp.h − Sr.No. Variable & Description 1 jmp_buf This is an array type used for holding information for macro setjmp() and function longjmp(). Library Macros There is only one macro defined in this library − Sr.No. Macro & Description 1 int setjmp(jmp_buf environment) This macro saves the current environment into the variable environment for later use by the function longjmp(). If this macro returns directly from the macro invocation, it returns zero but if it returns from a longjmp() function call, then a non-zero value is returned. Library Functions Following is the only one function defined in the header setjmp.h − Sr.No. Function & Description 1 void longjmp(jmp_buf environment, int value) This function restores the environment saved by the most recent call to setjmp() macro in the same invocation of the program with the corresponding jmp_buf argument. Print Page Previous Next Advertisements ”;